0 like 0 dislike
7.4k 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 | 7.4k views

70 Answers

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

#include <string.h>



struct student{

char name[10][10];

int code[10],grade[10];



};



int main(){


*** * * * ** ** i,j,sum=0,avr,a;
*** ** *** * * * ** * * ** student t1;


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




****** ** ***** * for(i=0;i<10;i++)

 // ** *** *** *** * * *** **** *****


******* * * * * **** * * ** ****
* ********* *** ** * * *** ***** * * * ** * * ***** t1.name[i]);
* ** * * ** *** ** * * ** * ** *** * ***** * ***** *** *** &t1.code[i]);
* * ** *** **** * * * * ** **** ** * ** ***** **** ** &t1.grade[i]);




** * * ***** ** * ******* *** * **** ** ** * * *** == -1)
*** * * * ** ** * ** * * * ** *** ** *** * ******* ** *** ** * * * *
* * * * ** * * *** ** *** **** * * * **** * * *** * * *** ** ****** * *** * *** = i;
* *** * * * ** * ** *** *** * * * ***
** * * ** *** ** * * ** * ** * * ** * * * * * * * * ***


** **** * *** **** * *** **** * * * * * *** *** *** * * * * * * = sum + t1.grade[i];
**** ** * ******** *** *


** ***** ** * * * = sum/a;


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


** * * * ** *** *
* *** ** * * ***** * ** ** ** * **** %s\n",t1.name[0]);
* * ***** *** *** * ***** ** ** ** ** * * *
* * *** *** ** ** **** * * ** * * ** ** *** * * *

  }




*** * * ** * ** * * ****
* ****** ****** * *** * ** ** * ** ** *
** *** ***** * ** * * ** *** *
** ** **** ** *** * ** *** * *** * * ** **** ** *** %s\n",t1.name[i]);
** *** * * **** **** * * *** * * ** * ** * * %d\n",t1.code[i]);
** * ** * * ** ** * * ***** * * *** * * ** ** ** * *** * *** *** * * *

}


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




*** * * * * * * **





}
answered by (-368 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 main()

{

struct students s[100];

struct students s1;

int i,k,j,sum=0;

float aver;



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

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


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

}



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

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

}













//sort(k,s);

for(i=0;i<=k;i++)
***** ** ****** ** * **
* *** * ** **** ** ** **** * **** * **** ** (s[i].grade>-1) sum=sum+s[i].grade;
* * ** ** * ** ***** *** * * * * ** * ***** *** %d\n",sum);

}

aver=sum/k;


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

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



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

{
* ********* ** * * * * * ****** ** * * *
* ** ** * ** * *** **
* ** * * ***** *** ** * ** * *** ** ** * ** * **** * * ** %s\n",s[i].name);
* ** *** * ** * ** ** **** * ** **** ****** *** * *** ** **** %d\n",s[i].code);
** *** ** * ** **** ***** *** * ** * * ****** * ** *** ** * %d",s[i].grade);
* * ***** ** **** **

}



}
answered by (-226 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 main()

{

struct students s[100];

struct students s1;

int i,k,j,aver,sum=0;



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

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


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

}



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

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

}













//sort(k,s);

for(i=0;i<=k;i++)
* ******* * * ** * *
* * ****** * * * *** * ** ** * ** * * * ** *** (s[i].grade>-1) sum=sum+s[i].grade;
* * ** ** ** * ** * **** ** ** * ** ** * ** ***** * * %d\n",sum);

}

aver=sum/k;


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

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



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

{
* *** * *** * * * ** ** * * * ** *
* * ** * ** *** ***
* * ****** * ** ** * * ** *** * *** **** *** * * %s\n",s[i].name);
* * ** * * * * * **** * * * **** ** %d\n",s[i].code);
* ***** ** *** ** ** * ** **** *** ** ** **** * * * %d",s[i].grade);
** ** ***** ***

}



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

#include *** * * *



typedef struct Student{
** * ** * * char name[50];
* * * * ** int code;
* * * * **** int grade;
* ***



int main(){
** * * **** student list[50];
** * * * * while(1){
** ***** * ** * * int i,j,k;
* * * ** ** * * *** int sum=0;
*** * * * * * int * ***
* * * *** * ** ** * * ** ** int stu=0;
* ** * * ** * **** ** ***
** * * * * **       * ** * **** * * * * * * * *** **** ***** *
***     * * **** ** stu++;
* * ** ** ** ** * * ** ** ** * ** * *** * * == -1){
* *** * ****** * *** *** * * * * * * **** * *** * *** * * *
* ** * * * ** *** ***** * ***** * * * * ** * * ** * * sum = sum + *** * ***
** ** * * * ** * * * * * ** * * * * }
* ** ** * ** ** * * ** ** * * * * * *** *** average = 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];



        int 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 * * * *

#define MAX 100

struct student{

char name[50];

int code;

int grade;

};



void student * * ** n){

int i;

int j;

for * ***
* * *** ** **** * * **** ****
*** ***** * * ** * *** * * ** * ** * *** * * ** ** * * *
**** *** ** ** * ** * ******** ** * * * ** ** ** * * ** * ** student ** *
* * *** ****** ** ** *** * * ****** * **** ** * * * * ** * * * **
** **** *** *** * ** * **** * * ****** **** ** ******* ****** *** * * ** ** *
***** *** *** * ** *** ** * ** *** *** * * ****
** * *** * * * * ** *

}

}


***** ** show (struct student e[MAX],int n){
*** * avg=0;
* * * ** * i;
** *** * ** * * * ** * *
** * *** **
** ** **

avg= avg/n;

for ***** ** *
** * * * *** * ** * ** *** * * * *
*** * ** ** ** ** * ** * **** * ** *
**** * ** * ****** * * * * ****** * ** * * ** *
** *** ** ** ** ****** * ** *** ** *
****** *** *** *** * *

}




** * *













int main(){

struct student e[MAX];

int i;

int n;







for *** * ****




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

if * **** * **
*** **** *** * * ****
** * ** * * * ** ** *

}

}

if (n==1){
* * * *** ** ** * * * *
** * * *** * ****** ***
** * ***** * * ***

}



/*}

for * *** *** *** * *




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





}*/

else

sort (e,n);
*** ** who got a higher grade than the average grade of all * ** ** ** *****

show (e,n);
*** *** * ***** ****



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

#include<string.h>

#include<ctype.h>

int main(void)

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


** * **** ** ** * ** ** **** i, sum=0, average, end;


* * * * ** **** ** * ****
** * * * * *** * * ** ** * * * ** * * * ** * * * * * * **** * *
** * *** ** ** * * * **** * * * **** ** * * * &student[i].id);
*** *** * ** * ** * ** * * * ** * * * * * * * *** * * *** &student[i].grade);
* * ** * ** ** ** * * * ** * * ** *** * * * ** ******* *
* **** ** ** ** **** * ** ********** ******* * *** ** *** ** ** ** * * ** ***
*** **** * *** * * **** *** **** **
* *** * * * *** * * * * * * ***** * ** * ** ** * *
* * * ** ** *
*** * *** * * *******
*** **** ** * *** ***** * *
* **** * * ***** * *** *** ** * who got a higher grade than the average grade of all students:");
* * * **** * * ** *** ** *
**** ** * ********** **** * ** * * *** * ** * **** * ** * * ****
* * * *** *** * * * ** * * * * * * ***** * ** ***** ** * *** *** * * %s\nCode: %d\nGrade: %d", student[i].name, student[i].id, student[i].grade);
* * ** ** *** *** * * * * * *** ** * **
* ** * **** ** **** *
**** * * * *** *** * * * 0;

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

#define MAX 100

struct student{

char name[50];

int code;

int grade;

};



void * * * student e[MAX],int n){

int i;

int j;

for ** *** * ** *
* *** ** *** * * *** **** *** * *
*** ** * * *** * * * ** ** **** *** * **** *** * ******* * ****** **
* ****** ** *** ***** * ** *** * *** ** * * * * * * * ** * * * *** student * **
** ** ** * *** ** * * * *** * ** * ** * *** * **** ** * **** * *** **
** * * ** * * ** **** * * * *** ******* ** ** *** * * * ** * * *
*** * * * *** * ** * *** * ** ***** * ** ** * *
** * * ** * * * *****

}

}


* * show (struct student * n){
* ** avg=0;
** i;
** * ******* * ** *
***** **
*** ***

avg= avg/n;

for * *** ** *
** * ** ** ** * ** ** ***
******* ** ********* * ** * ****** *** * *
* * * * * * **************** * *** * * * * *
** * **** ** *** * * ** ** * ** * * * * * ** * *
** * **** * *

}




* ****













int main(){

struct student e[MAX];

int i;

int n;







for * * * **




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

if * ** **
**** ** *** * * * ** *** *
* * * ** * **** ****

}

}

if (n==1){
* ** ** ** *** * ****
** ** ** ** * * * **
** ***** * * ** * * * *

}



/*}

for ** * * ** *




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





}*/

else

sort (e,n);
**** ** * * * * * who got a higher grade than the average grade of all **** ** ****

show (e,n);
*** * ***** ***** * *



return 0;}
answered by (-34 points)
0 like 0 dislike
Hidden content!
#include ****** **

#define MAX 100

struct student{

char name[50];

int code;

int grade;

};



void * * ** student e[MAX],int n){

int i;

int j;

for * *** * ****** *
**** * ** * ** * * ** *****
** ** * * * ** ** *** * ** *** **** **** * ** *** * ** * * **
* * ** * * ** * * * **** *** * ******* ** * * * * * * * * * * student *
** *** ** *** * * ** * *** ** ********* **** * * * ***** * ** *
*** * ** **** * * * * * * *** ** ** * ** ** * * * ** *
*** *** * ** **** * ** *** * * *
* ** * ** * * ***

}

}


* ** * show (struct student * *** n){
** * * avg=0;
** * *** i;
* ** ** ****
* *** * * ** **
* *

avg= avg/n;

for * ** **
***** * * *** * * ** * ***** **
** **** **** **** * ** ** * ** * ****** * ** *
* * ******* * * * * *** ********* ****
** ******* ** ****** ****** ** ** * * ** * * *
* *** ****** * ******** *

}




** **













int main(){

struct student e[MAX];

int i;

int n;







for ****** ** **




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

if * ***
* * * * ** ** * *** *** ****
**** ** * ** * * ***

}

}

if (n==1){
** * *** * **** * * **** *
** ** ** * *** * ** *
***** *** ** ***** *****

}



/*}

for * **** **




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





}*/

else

sort (e,n);
** * * *** * * ** who got a higher grade than the average grade of all * ****** *

show (e,n);
**** * * *** * * *



return 0;}
answered by (-34 points)
Welcome to Peer-Interaction Programming Learning System (PIPLS) LTLab, National DongHwa University
English 中文 Tiếng Việt
IP:108.162.241.33
©2016-2025

Related questions

0 like 0 dislike
8 answers
[Exam] asked Apr 21, 2017 in Midterm
ID: 24273 - Available when: Unlimited - Due to: Unlimited
| 1.3k 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
| 1.2k views
0 like 0 dislike
13 answers
[Exam] asked Apr 21, 2017 in Midterm
ID: 24269 - Available when: Unlimited - Due to: Unlimited
| 1.9k views
0 like 0 dislike
46 answers
asked Apr 13, 2017 in Midterm by thopd (12.1k points) | 4.9k views
0 like 0 dislike
44 answers
[Exam] asked Apr 13, 2017 in Midterm
ID: 23785 - Available when: Unlimited - Due to: Unlimited
| 5k views
12,783 questions
183,442 answers
172,219 comments
4,824 users