0 like 0 dislike
1.5k views

Write a program with following requirements:

  • Define the structure type student with fields: name, code, and grade.
  • Write a function to sort the structures in grade ascending order and another function to display the data of the students who got a higher grade than the average grade of all students. If there is only 1 student in the list, display the data of that student.
  • Write a program that uses this type to read the data of 100 students and store them in an array of such structures. If the user enters the grade −1, the insertion of student data should terminate. Then print the data of the students who got a higher grade than the average grade of all students. 

 Example input:

Edgar
20161123
78
Robert
20161523
75
Rebecca
20166123
66
Todd
20161673
86
End
1
-1

Example output:

Students who got a higher grade than the average grade of all students:
Name: Edgar
Code: 20161123
Grade: 78
Name: Todd
Code: 20161673
Grade: 86

 

[Exam] asked in Midterm
ID: 23789 - Available when: Unlimited - Due to: Unlimited

reshown by | 1.5k views

70 Answers

0 like 0 dislike
Hidden content!
#include <stdio.h>

#include <stdlib.h>

#include <string.h>



struct data

{
***** **** ** ** ** ** name[20];
* * ** * * *** *** ** code;
*** * *** * * * * * grade;

};



void compare(int num, struct data a[])

{
** ** * ** **** * ** i,j;
* **** ** ** ** *** ** ** * * data temp;


*** ** * *** **** * ** (i=0; i<num; i++)

    {
* * **** ** ** * * ** ** * *** * (j=0; j<num; j++)
******* * *** * ***** **** ***** * *** * * * * *
** ** * ** * * ** * ** * *** * * * * * * ****** * (a[i].grade<a[j].grade)
* *** * * ** * * * **** * * * **** *** * ** **** * * ***** ** *
* *** * * * * *** * * ** * ** * ** * *** ** * * ** * *** ** * ** * ****** ********* = a[i];
* * ** * *** ** * *** ** **** ** * ** ** * ** ** ** *** * * * * *** ** ******* ** * = a[j];
* * ****** * **** * **** ** ** * * * * * ***** * * * * * **** * * ** * * ** * ****** * ***** = temp;
* *** ** ** ** ***** * *** * * ** ** * * * ** ** * ** *** * * *
** * ** ** ** * ** ***** ** * * ******* *
* *** ** *** * ***** *

}



int average(int num, struct data a[])

{
****** **** *** * ***** **** * i,sum=0,ave;


** * * * ** ** * * * *** (i=0; i<num; i++)
* * * ** ** * *
* * * * * * ** * *** * * *** * *** * * ** *** += a[i].grade;

    }
* * * * * * * *** * * ** = sum/num;


* ** * ** * * ** * * * * * * ** who got a higher grade than the average grade of all students:\n");
** ** ** * ** * * ** (i=0; i<num; i++)

    {
* * * * **** * * ** ***** ***** ** * **** * ** * (a[i].grade>ave)
* * * * **** * * **** * ** ** **
** ** ** ** * * * * * ** **** * ** ** *** ** * * * ****** * ** ** ** ** ** * **** *
* ***** ** *** * * ** *** * * * * * *** ** *** ** * * **** * * *** * *** * * * ** ***
*** * * * * * * * **** * ** ** ** * * ** *** *** * * * *** * ** * * ** * * ** *
** * * ***** * ** * **** *** * *** * * * ***
* ** ** * * *** ******
* * ** * * ** *** *** 0;

}



int main()

{
* ******* * **** ** ** * * data Student[100];
* **** * ** ** ** * * i,num=0;


** * * * ***** * ** * *** (i=0; i<100; i++)

    {
* * * *** * ** * * * ** ** ** * * ** ** **** ** * ***** * ** * * ***
*** ** ****** ** * * * ***** * **** * *** ** * ***** * *** * * * **
*** ** ** * * ** * * * *** * * * * * * ** * ** ** *** * **** * ** *** * ** **
* * * * * * * * * * ** ** * * * ** *** ** * **** (Student[i].grade == -1)
* *** * **** ***** ***** ** * ****** * * * ****
**** **** * ** * ** * * *** **** * * * * ** * ** *** * * * * *
** ** ** * * * * ** **** ** ** * **
** * ** * * * **** ** ** *** *** * **** *** * * *

    }
** ** ** * ***** * * * * *****
***** * ** * ***** * *** * ***
**** ******* ** ** * *** 0;

}
answered by (-190 points)
0 like 0 dislike
Hidden content!
#include <stdio.h>

#include <stdlib.h>



typedef struct Student{

    char name[50];

    int code;

    int grade;

}student;



int main(){

    student list[50];

    while(1){
** *** * ** *** * ** **** * ** *** * * * i;
* ** * * **** * ** *** * *** * ** ** sum=0;
* ***** *** * ** * *** ***** * ** ** * ** average=0;
* * *** * ***** *** ** ** ** ** ** * *** stu=0;
*** * * * * * ** ** *** * * *** **** ** * * *
******** ** * ** **** ** ** ******* ** ** * ** * ****** **** * ** ** * ***** * *** * *** ** ** ** ** **** *
*** * *** ** ** * * *** * * * *** *** * * *** * * ***** **
** * * ** * * * * * ****** * ** * *** * ****** ** ** ** * == -1){
** * ** * ** ****** **** ****** **** ** **** **** ** ** * **** *** *** ** * * ** *** ** * ** ** * *** *
* ** * ******** * * **** * * ** **** * * * ** *** * ** * * *** * * *** * * * * * * ** * * * = sum + list[i].grade;
* ** * ** ** * * ** * ** ** * * * ** ** * **** * ** * * * * ** * * * * * * ** *
*** ****** **** * ***** * ** * * ** * * * ** ** ** ******* *** ** ** *** * * ***** = sum / (stu-1);
** * ** * * *** ** **** *** * ***** **** *** * *** **** * * ****** **** ** **** ** **** * * *** ***** ***
* * *** *** * * * * * *** * **** * ** * * * ** ** * ** ** * ** * * *** ** * * ** * *** ** * **** *** ***** ** * * ** * * * ** ***
* *** * ** * *** * ** *** ** * * ****** * * * ** ** * * *** * ** * ******* ** **** ** * ** **** * ** * ** *** ***** ***** ** *** *** *** * **** ** * * * ** * ** ***
*** ** * * * * * ***** * * *** ******* * * ** * **** * ** * ***** ** * * ******* **** * * * ** ** *** **** * * *
* ** ** ** *** * * ********* * ** *** * ***** **** * * * **** ** *** * ** **** **
* * * * * ** *** * * ** ** ***** ** ** ** **** **

        }

    }

    return 0;

}
answered by (24 points)
0 like 0 dislike
Hidden content!
#include <stdio.h>

#include <stdlib.h>



typedef struct Student{

    char name[50];

    int code;

    int grade;

}student;



int main(){

    student list[50];

    while(1){
** ** * * * ** ** ** * * * * * * ** i;
** * ** ** ** ** * **** * *** * *** ** * * ** sum=0;
** * ** ** * * * * **** * ** *** average=0;
* ***** ** **** * ******** * * ** * * **** * *** ** * ** stu=0;
* * * *** * *** * * *** * *** * * * * * * *
* * * * *** * ** * * *** ** * ** * * ** **** * * ** ** *** * * ** * ** * *** * * ** * * * ** * **** * * * * *
** ***** * ** *** * **** ** * * * * ** * ** * *** * **
* * * *** **** * ***** ********** * ** * ** *** ** * ** * *** * ** ** * ** * == -1){
** * *** * * * * ** * **** * ** *** * ** ** ** *** * * * ** **** ** * ** * * *
*** *** ***** **** * *** ** **** * * * *** ***** * * * **** * ****** * * *** ** *** * * * * * * * ****** ** * ** = sum + list[i].grade;
**** ** * ******** * ** ** ** **** ** * *** * ***** ** * *** *** * * ** *
** **** * ** * * ** * *** * *** ** * *** ** * *** ** * *** * * * * ** ** * *** * ** * * = sum / (stu-1);
* * ** * * ** * ***** *** * * *** ** ** * *** ******* *** * * * *** *** ** * * *** ** * ** ** **** * ** * * *
* * *** ** * ** ** * *** * * * * *** ***** * * * * * * * ** * * * * **** ** * * ** ** * * *** *** * * ** ********* ** *
**** *** **** * * ***** * **** * ** * ***** * ** * **** ** * *** *** * **** * * ** * * * * * * ***** ** **** * *** * * ** ** ** ** ** ** * ** * ** *** ** * * * * ** * *****
* ** * ***** * * * * * ** *** **** *** * * ** * ** ***** * * ** *** * ** * * * ** ***
**** * *** ** * * ** ** ** **** *** ** *** ** *** * ** * ******* * * * * **** **
* * * * **** * **** * ****** ** * * ****** * ** *** ** *** **

        }

    }

    return 0;

}
answered by (24 points)
0 like 0 dislike
Hidden content!
#include <stdio.h>

#include <stdlib.h>



typedef struct Student{

    char name[50];

    int code;

    int grade;

}student;



int main(){

    student list[50];

    while(1){
*** ********* * *** *** * ** ** * **** **** i;
**** * * ** * * * ***** *** * ***** * **** sum=0;
* *** ***** * ** * * ** * ** **** *** * * * average=0;
** **** * **** * * * * ** * **** ** * * **** stu=0;
*** ***** ** ** * * ** * **** * ** * ***** *** *
* *** ******* * * ***** * *** * * * * ** *** * ***** ** * ***** * ** * * ** ** * * *** * * ** * * *** ** ** *
***** ** ** * ** *** *** * * ** * * ** * *** * ***** **
** * *** * * ** ** *** **** * * ** *** * *** * ** * ********* ***** * == -1){
******* ** * * **** * **** * * * ** * ** * * * * *** * *** **** * * * *** ** ** ******* ** * **
****** **** * * *** ** ** ** *** * ** **** * ** * * * ** ** * * ** ** * * * * ** **** *** * * = sum + list[i].grade;
** * ** * * **** * ** ** ** * *** * * * *** *** * * * ** * *** ** * * ******
**** **** * * * ** * * ** *** *** * * *** * * * ** * * ** * *** **** * ***** * * ** * * = sum / (stu-1);
**** ** ****** ** ** *** **** * ** *** ***** * ** *** ** *** *** ****** * ** ** *** * ** *** **
* ****** * ** * *** * **** ** ** **** *** * *** ***** ** ** ** * * *** * ***** * * ******** *** * * * *
**** *** * ** ** * *** * *** ** * ** * *** **** ***** * *** * * ** * **** ** * ** ******* * ** *** **** *** * * * *** ** * **** ** **** * * * ** ** ** * *
** ** ** * * * *** ******* * ** * *** * * * * *** * ** * * * ** *** * ** *** ** * *** * * ** **
* * * ** ** * *** * * * * ****** ** * * **** *** * * * * ** * *** * * * ** * *
* ****** * * * * *** ** *** * ******* **** * * * *

        }

    }

    return 0;

}
answered by (24 points)
0 like 0 dislike
Hidden content!
#include <stdio.h>

#include <stdlib.h>



typedef struct Student{

    char name[50];

    int code;

    int grade;

}student;



int main(){

    student list[50];

    while(1){
* ** * * ** * ***** *** * * **** ** * * * * * *** * i;
*** *** * ** *** ** ** ** *** * * * * * *** sum=0;
* *** ** ** ** **** ** * * ** ** ****** ** ** ** average=0;
** * **** ** ** ****** *********** *** * * * stu=0;
* ** * * * ** * ***** ****** ** * ** * *** * * *
* ** * * * **** * * * * * * ** * * * * ** * * * * * * * * * * * ***** ** * ** *** ** ** * * * ** ** * * *
* *** ** * * ** ** * ** * *** * ** ** *** * *** * * ** ** ** **
* ** * *** *** ** ** * * ** ** * * * *** ** * * **** *** * **** * == -1){
** * ** * * *** * * * * * * * ***** ** ** **** * *** * * **** **** ** * **** * * * ** * * *
*** * * * ** * * * ** * * * * **** *** * ***** * *** ** * * * * *** * * * * *** * **** **** * = sum + list[i].grade;
** **** * ******* * ** * ** * **** ** * *** * ** ******** * * * * * * ***** *** ***** *** ** * * * ** *
**** * * * *** *** * * ** *** ** ** ** * ** * *** ******** ** * * * * ** * = sum / (stu-1);
****** **** * * * ** * * ******* * ** * * *** * * * * ** * ** * **** * **** * *** ** *
** *** *** * * * ** ** * * ****** * * *** ** * * * * ** ****** * * *** ****** * ** **** ** ** * * *** * * * *** * * * ** *
* * * *** ***** *** *** *** * ** * * **** * * ** * **** ***** ** ** * *** ** * *** * ** * ** * * ** * *** * ** ** * ** * * * ** ******* ** * * * * * * * ***
**** * **** **** * * *** * ** * * * *** ** * *** * ** * * * * * ** * ** * * * ** ****** **** *** * * * *
* **** * ** ** ** ** * **** ** * ** * ** * ** * * * * * * *** * * * * **
*** * ** * ******** ** *** * * * * * * * * *** ** * * ****** ***

        }

    }

    return 0;

}
answered by (24 points)
0 like 0 dislike
Hidden content!
#include<stdio.h>



struct students

{
***** * * *** * * ** * **** name[10];
*** **** * * ** code;
** ** *** **** ***** * ** * grade;

};



void sort(int k, struct students s[])

{

int i,j;

struct students s1;



for(i=0;i<=k;i++)

{
**** * * * * * ** * *
* *** * ** **** * * * * *
** ** ** * * ** * * * ** * * *** ** *** * ** ***
* * ** * ** **** ** ******* ** **** * *
* **** ** ** * * **** ** ** * ** *** *** *** * * * * * * *** ** * ** *
* ** **** * * ** *** *** * * *** * * *** * * * **** *** ** * *** * * ** *
* * *** * * ** * * * **** * * **** ***** * *** * * * *** ***
** ** * *** **** * * ** * * *** ** *** * **
* ** * * ***** ** * ****

}

}



int average(int k,struct students s[])

{
* ******* * ** * * ** i,sum=0,aver;


**** * * * * ** * ** * * ** *
** ** * ** * ** * **
* * * * * ******* *** ** ** * * ** *** * * **** * *
* **** * *** ** ** ***** * * * ** * *** ** ** *** *** ** %d\n",sum);
* *** * ***** * ** **
** ** ****** ** ** * * *
* * * **** *** * aver;

}







int main()

{

struct students s[100];

int i,k,aver;



for(i=0;i<100;i++)

{
* * * *** ** * * ** * * ** ** * **** *
* * *** *** ** * * * ***** ***** * *** * **
*** ** * ** * ** * ** ** * **** *** *** *


*** *** * ** * * ****** * ** *** **
* * ** * * ***
* ** * ** ***** ** * * *** * *** ** * ** *** **
**** ** * *** ** ** * ***** * ****** * **
* **** * ** * **** **

}

sort(k,s);

aver=average(k,s);
* * ** ** ******* ** *

printf("Students who got a higher grade than the average grade of all students:");



for(i=0;i<=k;i++)

{
******* * ** ** * ** * ** ** * * * * **
******* * ** *** ** ****
* * * **** * * * ****** * * * *** * *** * * * * * ** ** *
** * * * ** *** * ***** * * ** * **** * ** * * ** ** *** * ** *** *** *
** *** ** ** ** * *** *** **** ** * *** * ******** *** **

    }

}



}
answered by (-226 points)
0 like 0 dislike
Hidden content!
#include <stdio.h>

#include <stdlib.h>



typedef struct Student{

    char name[50];

    int code;

    int grade;

}student;



int main(){

    student list[50];

    while(1){
* * * * *** ** ** **** * * ** ** *** ** *** ** * * i;
** * * * ** * * ** ** *** *** ** * * sum=0;
** * ***** ** ******** **** * * ** ** * * * average=0;
** ***** ** **** * * *** ** ** *** *** * stu=0;
** * * * * ** * ** *** **** ****** ** * * * ***** ***** ****
* ***** ** * * *** ** *** * * * ***** * ***** * * * **** *** * * * *** ** * *** * * * ** ** **** * ** * *
****** *** * ***** * ** * ** ** *** * * * * * * * ** ***** *
******* *** * * *** *** **** ******* * * * * *** * ***** **** ** * *** ** ** ** == -1){
**** * ****** ** ** * *** * **** * * *** ** * * ******** * ** ** * ** * *** * ** ** * ** ********* * * **
* * * * * * ***** *** * ** * ** *** *** ** * * ** *** * * ** ** * ** * * ** *** ** ****** *** * **** ** ** * = sum + list[i].grade;
* *** ** * * ****** * *** ***** * * *** ** **** * ***** * * ** ** **** ** * * ****
* ** ** * * * *** * * *** ***** ** ** ** ****** * * ***** ** * *** ** * * *** * ** * = sum / (stu-1);
*** * * * ** ** * ** * * *** **** * * * * ** * **** ** * ** * * * *** **** * ** **** * *
** ******* * * * * * * * ** ** *** * * * * * ** * * * * *** ***** ** *** * * * * ** * ***** *** *
* ** * *** *** *** ** * ** * ** ** * **** **** * *** * * ** * ** ** * ** ** ** * ** *** ** ** * **** * ** **** * ** * **** ** * ** ** *** * ** *
* ** ** *** * ** * ** * * * *** * * *** ***** ** * * * ** * * ** * ** * * * * * *** ** * * * * * *
* * * * * * ******* ** **** * *** * * * * *** * * * * *** * * * * ** ** *
** ** ** *** *** *** * * ***** * ** ** * ******** **** *** * * *

        }
*** * ** *** ****** * * ** * * * * *** **

    }

    return 0;

}
answered by (24 points)
0 like 0 dislike
Hidden content!
#include<stdio.h>

#include<string.h>

typedef struct

{
** * ** * ***** ** * name[20];
** **** * *** * * * * * *** * num;
*** ****** * ** ****** grade;



}data;

int main(void)

{
* * *** ** * **** sol[100];
* ** ** * * * * * * *** * * * **
** ***** * ** * * ***** * **** i,j,sum;
* *** ** * * * **
* ** * * ** **** * **** **
** ** *** * ******* *** *

    {
** *** * * **** * ** ** ** * *** * *** * * ** * **
* ** *** ** ***** * **** ** * ***** * ** ** * * * * **** * * * *
* ** ** * * ** *** * * ***** * * * **** *** **** * ** * * ****** * **** ******


* *** * * * * *** * ** * ** * ** ** * * * ******* * ****
* * * *** * * * ** * * * * * *** **
** *** ** * ** ** *** * ** ** * ** * ****** * ***** **** ***** * **
***** * ** * **** * *** * * ** * ** * *
**** * *** **** * * * ** * ** ** * * ** * ** *** *
*** * * ****** * ** * ** ** ** * *** ** *** ***

    }
** * *** ***** * *** *** * **** ** who got a higher grade than the average grade of all students:\n");
**** * * * * *** * **** * ** * * *

    {


* ** *** * *** ** ***** ****** *** ** ** ** * * * ******
* * ** ** *** ** *** * *** * ** * * ** * **
** * ** ** **** **** ** * *** ** *** *** * * * * ** ***** %s\n",sol[j].name);
*** * * ****** ***** ****** *** ** ** ****** * ***** ** * * * *** * *** * %d\n",sol[j].num);
* **** * * * ***** * ** ******** ******** * * * *** * ******* * *** %d\n",sol[j].grade);
* ** ** ** * * ** * ** ** * *** *

    }
*** **** **** * * ** *** 0;





}
answered by (0 points)
0 like 0 dislike
Hidden content!
#include <stdio.h>

#include <stdlib.h>



typedef struct Student{

    char name[50];

    int code;

    int grade;

}student;



int main(){

    

    student list[100];

    while(1){
* *** * * * * * * * ** ** i;
* * * * *** * **** * ** ** **** * * *** * * *** sum=0;
*** ** ** *** * ** ** **** * ** **** * * *** ** average=0;
* ** * * ** * * * * * *** * * ** ** * ** ** stu=0;
***** * ** * * * **** *** * * *** * * *** * **** * *
* *** *** **** *** * *** ** ** * ** ** * ** * ** ** * ** * * ** ** *** ** ** * **** **** *** **** ** *
* * ** ** *** * **** * * * * ** *** ** * ** * * *** * *** **
*** * *** * * * * * * ** *** ** **** * * ** * ** *** *** * ** ***** ***** * * == -1){
*** *** ** *** * *** * ** * * * *** * * *** * * * **** * *** ** ** * * ** ** * ** ** **
* ** ** * ** **** * * ** * * * *** * * * * * * * ** * **** ** *** * * * * **** * * * * * * *** = sum + list[i].grade;
* ** * * *** * *** ** *** * * * * ** * ** * * ** ** ****** *** ** ** ** * * * **
******* * ** * * ***** ** * * **** **** * * * * * * * * * ** * ** * * ** ** * * *** = (sum+1) / (stu-1);
**** **** * * ******** ****** * * * * * **** ** * ** **** ** ** * * *** * * ****** * ** ****** **** *** *
* ** * **** ***** * * ** *** ** ** * *** ** * **** * **** * ** * ***** ***** * ** ** * **** ******* * ** * * * * * * ** **
*** ******* ********** * *** ** * * ** ** * * ** * * * ** *** * * * *** ** *** ** **** * **** ************ * ** * ** *********** * *** ***** ** * ** * *** * ***** ** * ***
* * ** ** * ** ** * * ** * * * ** * * ** * ** * ** ** *** ** ** * * * * * * * * ** ** ***
** * * * * * *** * * ** * * * * * ** ** * ** * ** * *** * ** ** * * * *** * ** * **
* * * * * * * * * * * * *** **** *** ** * * *** *** * * * ******* * ****** * * *
* *** ******* * * * * * ** * ** * * * ** ** * *

        }

    }

    return 0;

}
answered by (24 points)
0 like 0 dislike
Hidden content!
#include * * ** * * ** *

#define MAX_NAME 10

#define MAX_STUDENTS 100



typedef struct{
* * ** ***** * ** **** * * * name[MAX_NAME];
** ** * *** * * * * * * ** code;
* **** ** ** * * * ** grade;

}Student;



int main(void){
* ** * * ** ** * *** *** * ** * * * ***
** ** * ***** ** ** i, count=0, total=0;
** * ** * *** * ** * * * * avg;


* * *** ** * ** ** ** * *** i<MAX_STUDENTS; i++){
**** ** * * * * **** *** * *** * **** * *** ***** * * * *** * * * ** *
* ******* * ** * ** ** * * * * *** ** * ***** * ** *** * *** * ** *
* **** * * *** *** * ** * * * ** *** * * *** * ** ** * *** * * * * * * *****
** * * * * ** * *** * ** ** ** ** * * ** ** * ***


* ** ** *** * ** ** * * * *** * ** * **** ***** **** * * ********


** *** *** * ** ********** * * **** ***** ** ***** ** *** == -1){
**** * * ** * ** ***** * ** * * *** * * * * * ** *** ***** * ** * *
* * * * ** ** * ** * **** *** * *** ******* ** ** * *
***** ** ** * * ***** ** * * * * * *
*** * ** * *** **
* ** * * * * * *** ** * = (total+1)/count;
** * *** * * * * * ** * * *** *** ** who got a higher grade than the average grade of all students:", avg);
** ** * ***** ** ****** * *** * i<count; i++){
* ** * * * *** ** ***** * *** * * *** **** ** ** >= avg)
* * ** ** * * *** * * **** *** * ** * **** * * *** ** ** * * %s\nCode: %d\nGrade: %d", students[i].name, students[i].code, students[i].grade);
* **** ** * ******* *** *
*** ** *** * ** ** * ****** 0;

}
answered by (20 points)
Welcome to Peer-Interaction Programming Learning System (PIPLS) LTLab, National DongHwa University
English 中文 Tiếng Việt
IP:172.69.88.164
©2016-2024

Related questions

0 like 0 dislike
8 answers
[Exam] asked Apr 21, 2017 in Midterm
ID: 24273 - Available when: Unlimited - Due to: Unlimited
| 251 views
0 like 0 dislike
6 answers
[Normal] asked Apr 21, 2017 in Midterm by thopd (12.1k points)
ID: 24271 - Available when: Unlimited - Due to: Unlimited
| 242 views
0 like 0 dislike
13 answers
[Exam] asked Apr 21, 2017 in Midterm
ID: 24269 - Available when: Unlimited - Due to: Unlimited
| 339 views
0 like 0 dislike
46 answers
asked Apr 13, 2017 in Midterm by thopd (12.1k points) | 981 views
0 like 0 dislike
44 answers
[Exam] asked Apr 13, 2017 in Midterm
ID: 23785 - Available when: Unlimited - Due to: Unlimited
| 907 views
12,783 questions
183,443 answers
172,219 comments
4,824 users