0 like 0 dislike
520 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: 24273 - Available when: Unlimited - Due to: Unlimited
| 520 views

8 Answers

0 like 0 dislike
Hidden content!
#include ** **** ****

#include **** **** *



struct student_grade

{
*** * * * ** ** *** ** * code[100], grade [100];
** * ** * **** ** * * ** ** **

};

int main()

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


*** ** * * * * ** **** ** i<100; i++)
* *** ** * * * *
** * * *** * * * **** **** * *** *** *** * ** * * %d %d", s1.name[i], ** *** * * * * * *
* * * **** * * ** *** ** * * ** **** ** *** * **
** ** ***** ***** *** * *** ***** * * * ** * ** * *** *** *** * *
** **** * * * **** * * * ** ** **** * ** **** **** *
** ***** * *** ****


** ** ***

{
* * ** * **** * ** ** ****** who got a higher grade than the average grade of all **** ** *

}

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

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


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

}

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

#include ** ** *** ***

#include * ** ** * *** *

#define MAX 100



struct student{

char name[25];

int id;

int grade;





};





void sort(struct student e[],int n){

int i;

int j;



for ** **

for * ** ***** ** *
* ******* * * ** ** *** ** ** * ***** * ** * * * *** ** * * * *
**** * * * *** ** *** *** * **** ** ** ***** *** ** ** * * * ** ***** * student temp=e[j];
* * * ** * * **** **** ** *** * **** ** ** **** *** * *** ** * ** *** ** * * ** *
* ** * ** ** * ** ** *** ** * ***** ** * * *** * * * ** * ** * * ***** * * *
*** * ** *** * * * * *** *** ** **** *



}





}

}

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

int i;

int avr=0;



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

}

avr=avr/n;

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

}

}





int main(){



struct student e[MAX];

int n;

int i;



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

}

}

n=i;

if (n==0)
* * **** * * ** ***
** * * * ** ** * * *** ***** ** ** * ** * ** **
** * * ** **** ****** * ****** * * *** * *
** ** * * * **** * ** * **** ** * * ** **
* * *** ** *** ***

else

{


* * *


**** ** ** * ** who got a higher grade than the average grade of all * *** *


*** *

}

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

#include *** * ** *

#define MAX_STR 50

#define MAX_STUD 100



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

}Student;



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


* * * ** * ** * * ** i<MAX_STUD; i++){
****** * **** ** ***** *** **** * * ** * * * *** ** **** ** ****** ** *** *
* **** ** * **** *** * ** ***** * ** * ** ** ** ***** *
** * ** ***** **** ** ** * * **** ** ********* * * ** *** **** * ** * **** * *
***** ******* * *** * * * ** **** * **** * **
**** **** *** ** * * ******** ** * * ** += students[i].grade;
* * * * ** ** ** ** * * *** *** ** **** * *** *** == -1)
**** * *** * * *** * ** * * *** * ** * ** * * **** * * ** * * **
** ** *** **
* *** ** ** ** ** * * = (sum+1)/(count-1);
** ** ** ** * **** * * * who got a higher grade than the average grade of all *** *


* ** * *** **** * * * i<count; i++){
** * * **** ** * * * * ** * *** ** **** ************ * > avg)
** *** **** *** * ***** * *** ** ** *** ***** ** * ** ** ** * * * *** ** * %s\nCode: %d\nGrade: %d", students[i].name, students[i].code, * ** * * *
****** ** * * * *


* * * * * ** * ** 0;

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

#include *** * *



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

};



typedef struct Student Student;



int main(){
*** ** ** * *** * * i;
**** *** *** *** * lenght = 0;
** * *** **** * ** ** * * total = 0;
* * * * * * * ** * **** average = 0;
***** * * * * * **** * list[100];


**** * * **** * * ** i<100; i++){
* * ** * *** * * **** * * ******* * * list[i].name);
** ******* ** **** *** ** ** * ** *** * * * * list[i].id);
*** * * ***** * * * *** * *** **** * * ** ** * ** * * * * * *
**** * * * * * * ** * * ** * ** < 0)
**** * ** ** ** ** * *** * ** * * ** * ** *****
* **** * ********** *


** * ** * *** * **** = i;


* * * ****** *** ** * ** * ** i< lenght; i++){
** *** * ** * *** * ** * ** * * * ** **** += list[i].grade;
* *** **** **


* * * * * ********* *** ** = total / lenght;


** * * * ** * * ** * *** *** * ** * ** * who got a higher grade than the average grade of all * *****
*** * ** * * ***** * *** * ** * 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!
#include **** **

#include **** ****** *



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

};



typedef struct Student Student;



int main(){
* *** * * ** * ***** i;
** *** ** *** ** * * *** ** lenght = 0;
* * ***** * * * total = 0;
* **** ** * * ** ** ** average = 0;
** * * *** * ** ** ** * list[100];


* *** * * * ***** *** * ** * i<500; i++){
*** * **** * ** * ** * *** **** *** *** * * ********* ** list[i].name);
** ** * * * * * * **** * ** * * ** * * ** * list[i].id);
* * ** *** ** * ** * * * * * ** * * * ** * * * * * **
*** * ** * * *** ** * * *** *** * * * ** * * < 0)
*** ** * *** ***** *** * **** * ** * * **** * ** * **
* * ** *** * **** *


* * * ***** * * * * * * * = i;


* *** * * * ** ** ** * * * i< lenght; i++){
* ***** *** *** *** * * * ** * * ** * * * * ******* * += list[i].grade;
** ** * * ** * **


** *** *** ** * ** ** **** * = total / lenght;


*** ** * ***** * * * ** ** * ** * who got a higher grade than the average grade of all * *** ** ** *
** * * ** ** * ****** * * ** *** ** 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!
#include ***** ** * *

#include ****** * ** * *



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

};



typedef struct Student Student;



int main(){
*** *** * * * *** * ** i;
** * ** * *** **** lenght = 0;
*** * **** * * * * total = 0;
* * * * ** ** ** * * average = 0;
****** * * ***** **** * ** list[100];


* * * * * ******* ** i<500; i++){
* *** *** ** ** * *** ** * * ***** * *** * * ****** list[i].name);
* * ** *** * ** ** ***** ****** *** ** * * ** list[i].id);
* *** * *** ** * *** * * * *** *** * *** **** ** * ****
** ** * * * ** * ** ** ****** ***** < 0)
* ** *** * * ** ** * * ** ****** **** ******* **
* *** * * * * * * * * ***


* * *** * **** **** * = i;


* * * * * * ** * ** ** *** i< lenght; i++){
** ** ****** * * *** * * * ** * ** ** * ***** += list[i].grade;
** ** *** * ** ***


*** * * * **** ** * *** = total / lenght;


** **** * ******* * ****** * who got a higher grade than the average grade of all * * * * *
**** ** * * **** * ** ** ** * * * * * ** 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!
#include ** ** * * *

#include ** * ** ** *



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

};



typedef struct Student Student;



int main(){
* * * **** ** * * * ** * i;
* * *** * ** ** * * lenght = 0;
* * ** *** * * *** ** total = 0;
** ** ******** * * * average = 0;
* * ** * ** * ** * * * * list[100];


** * **** * *** ** ** * ** * i<500; i++){
* * ***** ** *** * * *** *** * * * ** ** list[i].name);
*** * *** *** ** ** ** ** ** * **** *** * list[i].id);
** ** * ** ****** ****** * *** * ***** * ** *** ** * * **** *
****** **** * *** * *** ** ** * * ** *** == -1)
** * ** ** * * *** ******** ** **** *** ** *
* * * ******* **


* * ** * ****** ** ** * = i;


* ** ** * * * *** ** *** i< lenght; i++){
* * ** * *** ***** ** * ** *** += list[i].grade;
********** * * * * *


* ** * ** ** ** **** * = total / lenght;


*** * * ****** * ** **** * * * ** * who got a higher grade than the average grade of all * ** * ****
* * * ** ** * * * * *** ** * ** * ** 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!
#include <stdio.h>

#include ** ********



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

};



typedef struct Student Student;



int main(){
*** ** * *** ** * **** i;
* * ***** * * ** ** * * * * * lenght = 0;
* * *** **** * * * * * average = 0;
** ** * * ** *** * *** **** * * list[100];


* ** * * ***** * i<100; i++){
* ** * * * * ***** * * ** * *** * ** *** ** * list[i].name);
* *** ********* ***** * * *** ***** ***** ** * list[i].id);
** * ** * * *** * ** *** * ** * *** * ** *** * * * *
* **** *** * * ** * *** ** * **** * * ** == -1)
* ** * ** *** *** *** * * * * * **** * *** *
* * * *** * * **


* ** * ***** * ****** ** = i;


* *** * * * * ** ** ** *** * i<lenght; i++){
** * * * * *** *** ***** ** *** * * * ** * ** * * ** * *** list[i].name);
** *** * * * ** *** * * * **** * * *** * * * * **** * ** * * list[i].id);
** ** * * **** ******* * ********* * * * *** ** ** list[i].grade);
** ** ** ** * *** *


** * * * ** * * ** * * i< lenght; i++){
* ** * * * ** * *** * * * ** * ** * += list[i].grade;
* **** * *** ** * *


* * ** ** ******** * * = average / lenght;


*** ** * * * *** ** ** * * *** ** * * * who got a higher grade than the average grade of all students:\n");
** ***** ** * * * * i<lenght; i++){
* * ** *** ** * * * *** **** ** * * *** * *** * > average){
* *** * **** ** * * **** *** ** ** * ** ** * **** ** *** ** * * * * * * * * list[i].name);
* * * ****** * **** * * ** * ** * * ** **** * *** ** **** ******* **** * * *** * ** ** list[i].id);
* * * **** ** **** * ** * * **** * ** *** * *** * ** * *** * ***** ** * * list[i].grade);
*** *** ** * * ** * * ** ** * ** ** *
* *** ****** ** * ** * * ** * ***


** * **** * *** * *** * * 0;

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

Related questions

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
| 453 views
0 like 0 dislike
13 answers
[Exam] asked Apr 21, 2017 in Midterm
ID: 24269 - Available when: Unlimited - Due to: Unlimited
| 800 views
0 like 0 dislike
70 answers
[Exam] asked Apr 13, 2017 in Midterm
ID: 23789 - Available when: Unlimited - Due to: Unlimited
| 3.2k views
0 like 0 dislike
4 answers
[Exam] asked Apr 21, 2017 in Midterm
ID: 24272 - Available when: Unlimited - Due to: Unlimited
| 373 views
0 like 0 dislike
11 answers
[Exam] asked Apr 21, 2017 in Midterm
ID: 24270 - Available when: Unlimited - Due to: Unlimited
| 659 views
12,783 questions
183,443 answers
172,219 comments
4,824 users