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

 

[Exercise] Coding (C) - asked in C
ID: 23560 - Available when: Unlimited - Due to: Unlimited
| 7.8k views
0 1
Called for Help
0 0
Called for Help
0 0
Called for Help

64 Answers

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

#include <string.h>



struct student_grade{
** **** ** ** * * code[100],grade[100];
** *** ***** ** * * * * * name[100][100];

};



int main()

{
** *** ** *** * * * * * sum=0;
** **** * * * * i, j;
* ** * * * ** * * *** * student_grade s1;


** * * ******** *** * ******* * * **
* * * * ** ** ** * * ** ** ** * * * ***** * * %d ** ** * **** * * ** ** ** * **
** ** * * ** ** * ** * ***** * ** ***** * ** == -1)
* * * *** * *** ** *** * * ** *** ** * * * ******** ** * ** *
* ** * ******** ** ** * ** * ** ** ** * ** *** * * * **
*** * *** * **** *
* ** * * * * * * * * /= (float)i;
** * ** **** * **** * * *** * ** * **** who got a higher grade than the average grade of all students:\n");
* * * * *** **** ** * *** * * * * ** *
* * * * * ** **** * * ** ** ** ** ** >= sum){
* * * * ** ** **** ** ** * * *** * * * ** * * ** ** ****** **** * *** %s\n",s1.name[j]);
* * *** * **** ** ** ** ** ****** * **** **** ** * ** ** * * ** ** * ***** ** ** %d\n",s1.code[j]);
* * *************** ** * * ** ***** * * * * ** * * * * *** * * ** ** * ** %d\n",s1.grade[j]);


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



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

#include <string.h>



struct student_grade{
* ** **** ** * code[100],grade[100];
** * * * ****** ** name[100][100];

};



int main()

{
* ** * ** ***** * ** * sum=0;
* * ******* ** * ** ** * i, j;
** ** * * * student_grade s1;


**** * * * ** * ** ** * * ***
**** * ** * ** *** ** * **** * *** *** *** * ** * * ** %d ****** *** * ** ** * * **** * ** ***
***** * * ** * * * * * * ** * ** ** * ***** ** ** *** == -1)
**** *** *** *** ******* * * * **** ** * *** * * **** * ** * * * * ***
* * ** *** * * **** * ** * ** * ** ******* ** * ** **
** * * * ** **** *
* ** * ** * * * *** ** * /= (float)i;
* * **** * *** * * * * ** * * * who got a higher grade than the average grade of all students:\n");
***** * * * * ***** * **** * * *** * * **
* *** * *** ******* ** ** ** * * ** ** *** *** * ** * >= sum){
* *** * **** ** ** **** * ***** * ** **** **** ** * * * *** * ** ** ** *** ** %s\n",s1.name[j]);
**** ***** ** * * ** *** * * * * * * ** * * **** * *** * * * ** ** * *** * %d\n",s1.code[j]);
* * * *** *** **** ** *** **** * ** **** * ** ** * **** ******* ** * * * %d\n",s1.grade[j]);


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



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

#include <stdlib.h>

#define MAX_STUDENT 3

#define MAX_NAME 10

#define MAX_ID 10



typedef struct{
**** * ******* * * *** * ** name[MAX_NAME], ID[MAX_ID];
****** * *** ** ** ** grade;

} stud;



int main(){
*** ***** * * * * * i, max=0, min=100;
* *** * ** * ** ** * students[MAX_STUDENT], *stuptr;


**** ** * * * * * * *** * *
* ** **** * * ** * ** * * ** * * ** != -1){
** * * ** * * * * *** ** * ** ** ** * * * **** * * *** ** * stuptr->name);
* * * *** * ** * ** ** * ***** * **** ** stuptr->ID);
**** * * * ** * * ** *** * ** * * *** ***** ** * * * ** * * &stuptr->grade);
* *** * ***** * ** ** *** * *** * ******* * *
** * *** **** * *** * **
* * ** * * *** * ** ** ** *** ** * *** **
* * * *** *** ** * *** * *** ** * ** ** ** * ** * stuptr->name);
** ** * ** * ** ** **** * * * * * ** * ** ***** * * stuptr->ID);
**** ** * * ** ** * * ** * *** **** ** ****** * ** * ** * &stuptr->grade);
* ** ** ** * * * * *** * ** * *** ** *
*** ********* *** *** **** *
***** * * * * *** * * ** **** * ** *
* *** * ***** * * ** **** * i=0; i<MAX_STUDENT; i++,stuptr++)
***** ** * * ** **
** ** * * ***** * * * ** * * ** * **** ** *** ** * ** > max)
* * * ** ** * * * * ** * *** *** * * * * * **** * * ** ** ** ** * * ** = stuptr->grade;
* * ** **** ** ** * ** * ** * ** * ** * * *** *** * < min)
* * * * ** * ** ** ** ***** * * * ** * * ** * * ***** ***** = stuptr->grade;
* * ** ** ******* *


* * * **** ***** * **** * * * ** i=0; i<; i++,stuptr++)
* * * * ** * * * * * **
* ***** *** *** * ** *** *** ** ** **** * ***** ***** * ** == max)
**** ** *** *** ** * ** *** ********
** * ** **** * * * * * ** * * * ** ** ** ** * * ** ** ** * * **** **** %s %d", stuptr->name, stuptr->ID, stuptr->grade);
* ** ** ** **** * ** ** ** * *** *** ** * ** * ** * * * * * ** * ** *** *
***** * *** * ** * ** * * *** ** *
* ***** ** * * ** ** **
** * ** * **** * ** * * ** * * i=0; i<5; i++,stuptr++)
* * * * ** *** * * *
* ***** * * *** * *** **** ***** * *** ** **** ** **** * * ** == min)
* * * **** * * * ** * ** * * * * * *
** * * * ******** *** * * * ***** * ** ***** ** * ** * * * %s %d", stuptr->name, stuptr->ID, stuptr->grade);
** *** * *** * * ** * * * ** *** ** * ****** *** ** * * *** ** * * * ** **
* * * * ** * * * * ** **** * * ** ** ** ** *
* **** ***** * **** **** *
*** * ** ** **** * * 0;

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

#include <stdlib.h>

#define MAX_STUDENT 3

#define MAX_NAME 10

#define MAX_ID 10



typedef struct{
* ** * * * ** name[MAX_NAME], ID[MAX_ID];
** *** *** ** ** * * * grade;

} stud;



int main(){
** * * * * ******** * i, max=0, min=100;
* ** * **** ***** ** * **** students[MAX_STUDENT], *stuptr;


* ** ** ** **** *** ***** ***** *
* * **** * ** * * * * * * * ** *** != -1){
* * ***** * * * ***** ** * * *** ** * ** **** * * **** * * * stuptr->name);
** * * * * *** * * * * * * *** ** *** * ** ***** * ** * stuptr->ID);
**** * * * ** * ** * ** *** * * * *** * * ** ** *** ** &stuptr->grade);
*** ** ** ** ** * ** *** * * * **
** * ** * ** ** **
* **** * *** *** * * * ** ** *** ** * **** ***
* * * ** ** * * ** * *** * *** * ** *** * ** *** ** * * stuptr->name);
***** *** * *** * **** *** *** ** *** * * **** **** ** ** *** ** stuptr->ID);
*** * * ** * * * **** **** * ** * ** * * ** * * &stuptr->grade);
** * ** * * ***** ** * * * * ** **** * ** ** * * **
* * *** * ***** **
*** ** ** * ***** *** * * * * ***** *
******* * * * *** * ** *** * **** i=0; i<MAX_STUDENT; i++,stuptr++)
* * * * ** * ** *** *
* *** *** ** * ** * * **** * * * * * * **** * * ** > max)
** ** *** * * ** * * *** ** ** * *** ** ***** * ** *** ** *** ** = stuptr->grade;
* * * * * ** ** * * **** ** **** * **** ** *** * < min)
******* * **** *** * * ** * *** ** ** * * * * ***** * ******** * = stuptr->grade;
** * ** * * * ** * * *


* ** * *** * * * * **** * i=0; i<; i++,stuptr++)
** ****** *** ** ** ***
* * * * * ** ** ** * * * *** ** * * *** ** * * == max)
** * * * ***** ** * * * * * * **
* ** ** * * *** ** ** *** ** * *** ******** *** ** ** * * *** ** *** * * %s %d", stuptr->name, stuptr->ID, stuptr->grade);
* *** ** ** * * * ** ** ** * ***** **** * ** ** ** * * ** * ** * *** **** * * *
* * ** * * * * * * * ** ***** *********** ****
* ** * *** ***** *** *
* ** * ******** **** * * * ** * i=0; i<5; i++,stuptr++)
* *** * ** ** * * * * *
** * * ***** * ** *** * ** ** ****** *** * ** * == min)
* * *** ** ** * * * * **** * * * ** *** * **
** ** ** ** ******* *** * **** ** ** ** *** *** * ***** * *** * * * **** %s %d", stuptr->name, stuptr->ID, stuptr->grade);
******** * * * * * ** * *** * *** ***** ** ** ** * * * ** * * ** *** ******
*** ** ************ ** ** *** * *** ****** * ******
* * * **** ** **
* * ** * ***** ** * *** * 0;

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

#include <string.h>



struct student_grade{
*** * * * **** * ** code[100],grade[100];
* **** *** * ** ** *** * name[100][100];

};



int main()

{
*** * ** ** ***** ********* sum=0;
* * * * * ** **** * ** * i, j;
* * * ** * * student_grade s1;


** * ***** * * ** * * * ** * * *
* * ** * ********* ***** * **** * * ******* **** * ** * %d ** * * ** ** **** *** * * * ** * **
* *** * * *** * * * * * * ** ** ** **** *** == -1)
** * ** ** ** ** ** * ** * ** * * * ** **** * * *** * * *** ***
* * ** ***** ** * * ** * ** * **** ** ** *******
* ** * * * *** *** ** *
** * * ** * * ** /= (float)i;
***** ** ** * * * * * ** ** * ** who got a higher grade than the average grade of all students:\n");
* * * * * *** *** ** ** * ** * *** ** ***
******** ** ** * * * * ** * ** * ******* * * * * * >= sum){
* * ** *** ******* * **** ** * *** * * ** * ** **** * ** **** * ** ** * * * %s\n",s1.name[j]);
** ** **** *** * *** * **** * *** ***** ** **** ******** * ** * * ********* ** * * * %d\n",s1.code[j]);
* * * * *** * **** *** * ** * ** **** * ** ** * ** * * ** *** * * %d\n",s1.grade[j]);


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



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

#include <string.h>



struct student_grade{
** *********** *** * code[100],grade[100];
** * * * * * * ****** name[100][100];

};



int main()

{
**** * * ** *** **** sum=0;
* ** ** **** * ** * i, j;
** ** ** * * * *** ** ****** *** student_grade s1;


* * ** * * ***** * *** * ********* ****
** *** ** **** * * * * **** * * * ** * * * ** %d ** * * ** *** *** *** **** * * **
* * * * ** * * * * **** * ** * * * * * *** * * == -1)
* *** * ***** ** * * * * * *** * * ****** * *
* *** * ** * *** * * ** **** * * ***** * * * *
* *** ****** * * ******* ** *
* * **** * *** * * /= (float)i;
* ** * ****** * * * *** * **** *** who got a higher grade than the average grade of all students:\n");
* ** * *** *** *** * * *** *
** * * ** ** ** ** * **** * * *** ***** * >= sum){
***** ***** ** ****** ** * ****** ** ***** * *** **** * * * **** ***** ** %s\n",s1.name[j]);
** ** * ** **** ** * * * * * ** *** *** * ** * * ** * ** ** ** * * %d\n",s1.code[j]);
* * * ****** * **** * * * * * ** * * * * *** * * ** *** * ** * * %d\n",s1.grade[j]);


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



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

#include <string.h>



struct student_grade{
* *** * * **** ***** *** code[100],grade[100];
* * * ** * * * ** name[100][100];

};



int main()

{
* * ** ** *** * * ** * * sum=0;
* * *** *** * * *** ** i, j;
** *** * **** * * * ** * * student_grade s1;


** * * ** **** * * * ** ** ** ****
** * * **** ** * * * **** * * **** ** ** ** * ** %d * * **** **** * ** * * *
** * ** * **** ** ** **** ** ** ** * * == -1)
* * * ** * ** * ** * ***** **** * ** * * * ** * ** ****** * * ** *
* * *** * * ** ** * * *** * ** ***
* ** *** ** * * *
**** * ** * **** * ** * /= (float)i;
* ** * **** ***** * ** * * * *** * ** * * who got a higher grade than the average grade of all students:\n");
* ** * **** ******* *** **** * **
* ** **** * * * **** **** ** **** ** ******* * ** * * * >= sum){
*** * * * *** ****** ******** ** * * **** * * * **** ** ** * ** **** ** **** * %s\n",s1.name[j]);
* * **** * ** ** * * * * ****** * * **** * * *** * **** * * * *** **** * %d\n",s1.code[j]);
* ***** ** * *** ** * * **** ******* * * *** * * **** * * *** *** * **** * *** %d\n",s1.grade[j]);


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



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

#include ** * * **



struct Student{
* ** *** ** * ** * * ** * name[20];
*** * * * ** * * * ** * ID[20];
** **** * ** * ** * ** grade;

};



typedef struct Student Student;



int main(){
* * **** * * * ** * ** * i, lenght;
* * * ** * * ***** average = 0.0;
***** ** * * ** *** * * * * list[100];
* * * ** * * ** ** * * i<100; i++){
* * **** * ** **** * ** *** * * ** ***** ******* * ** **** list[i].name);
** * ************* * *** **** * *** *** * * * * * ** ** * * list[i].ID);
** * * **** *** * ** * * * ** ** * **** * **** * * * ** ** *
** ***** ***** ** ** * * ** * * * * ** * < 0)
* *** * ** * * ******** * * *** * ** ** ** *** **
** ** * * * ** *
** **** ** * *** *
** * ** * * * ** = i;
**** ***** * *** ** * * * *** i<lenght; i++){
** **** *** ** ****** ** ** * *** * *** ** ** += list[i].grade;
*** * * * * *** ** *
*** * * *** *** * **
*** *** * ** **** * = average / lenght;
*** ** * ** **** * ****** * * ** * average);
* * *** **** * ** * **
** * ******** * ***** * ** * who got a higher grade than the average grade of all students:\n");
* * * * * ** * ** * * i<lenght; i++){
* * ** ** * *** *** * ** * * ** * *** > average){
*** * ** ***** *** ****** **** * * ** ** * * * * * ** * **** **** * * * * * ******* %s\n", list[i].name);
** ******* * * * * *** **** * *** ******* * * **** ** * ** ** * ** %s\n", list[i].ID);
** ** *** *** **** * * * ******* * * *** * ** * * * ** * * %d\n", list[i].grade);
*** * * *** **** * * ** ** ** * ** * *
** ** ** ***** ** *
**** *** *** * * * 0;

}
answered by (-188 points)
0 like 0 dislike
Hidden content!
* * *** * * * * *
* MAX 100
** ** * ***** ***







struct student

{
* * ** * * * * ** ***
*** *** **** **** *** * code;
* * * ** *** *** * * grade;

};



void * ** * * ** ** ***** n)



{int i;
* * j;


*** **** * * (i = 0 ; i * * ( n - 1 ); i++)
* *** * * ***
** * * ** ** **** * ** * (j = 0 ; j **** n - i - 1; j++)
** *** * * ***
** *** ***** ** *** ** * * * ***** ** *** *** * ******
* * ***** *** * * ********
* *** ** * * ** * ** * * * * * ** * * ***** student temp * **** * e[j];
**** * *** *** ** * ** ****** ** *** ** * *** * ****** e[j+1];
* * * ** ****** * * * * * ****** **** = temp;




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









}



void * * * ** * n)

{int avr=0;
****** * i;


**** ** *


* ** **** *



}
*** *


* ****** ** **



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

}

}





}

int main ()

{

struct * * *

int i;

int **

int n;



while ** * *



{



for * ******



{


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



}



}



}



n=i;



if *


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



}



else
***


** **










* * 0;

}
answered by (-34 points)
0 like 0 dislike
Hidden content!
* * **** * ** **
** * MAX 100








* * ***

{
* * *** * *** * **** * ** * * ****
** * *** *** * * ***** code;
*** * ***** * *** * grade;

};



void student * ***** n)



{int i;
* ** * j;


* * * *** ** (i = 0 ; i ** ( n - 1 ); i++)
* * *
** ** **** ** * ******* (j = 0 ; j **** n - i - 1; j++)
* * ** * *** *** *
** * * * ****** *** * * ** **** *** * * *** * ****
** ** * ** * ** * *** ** * ****
* * ** * * ****** * ** *** * ** ** ** * ** ** * * ** student temp *** * *** * e[j];
* * * * * **** **** * * * * * ** * ** * ** * ** * * **** ** * *****
* * * *** ** * * ** * ** * * ** * *** = temp;
* * **** *** ***** ** *** * * *
*** * ********** ** ***** ** *
* * *** *









}



void * * * * **** n)

{int avr=0;
* * * i;


* **** ***


*** **



}
** * *


* * ** ***



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

}

}





}

int main ()

{

struct student * *

int i;

int flag=0;

int n;



while *



{



for *** * ** ***



{


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



}



}



}



n=i;



if * *


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



}



else
*** *
** * *










* * 0;

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

Related questions

0 like 0 dislike
32 answers
[Exercise] Coding (C) - asked Apr 6, 2017 in C
ID: 23557 - Available when: Unlimited - Due to: Unlimited
| 4.5k views
0 like 0 dislike
18 answers
[Exercise] Essay (Open question) - asked Apr 20, 2017 in C
ID: 24219 - Available when: Unlimited - Due to: Unlimited
| 3.4k views
12,783 questions
183,442 answers
172,219 comments
4,824 users