0 thích 0 k thích
1.6k đã xem

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] đã hỏi trong Midterm
ID: 24273 - Xem được từ: Không giới hạn - Hiệu lực đến: Không giới hạn
| 1.6k đã xem

8 Trả lời

0 thích 0 k thích
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]);


* * ** *** * * *

}

}
trả lời bởi (-48 điểm)
0 thích 0 k thích
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;}
trả lời bởi (-34 điểm)
0 thích 0 k thích
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;

}
trả lời bởi (20 điểm)
0 thích 0 k thích
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;

}
trả lời bởi (-188 điểm)
0 thích 0 k thích
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;

}
trả lời bởi (-188 điểm)
0 thích 0 k thích
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;

}
trả lời bởi (-188 điểm)
0 thích 0 k thích
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;

}
trả lời bởi (-188 điểm)
0 thích 0 k thích
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;

}
trả lời bởi (-188 điểm)
Welcome to Peer-Interaction Programming Learning System (PIPLS) LTLab, National DongHwa University
English 中文 Tiếng Việt
IP:172.70.80.197
©2016-2025

Những câu hỏi liên quan

0 thích 0 k thích
6 trả lời
[Normal] đã hỏi ngày 21 tháng 4 năm 2017 trong Midterm bởi thopd (12.1k điểm)
ID: 24271 - Xem được từ: Không giới hạn - Hiệu lực đến: Không giới hạn
| 1.4k đã xem
0 thích 0 k thích
13 trả lời
[Exam] đã hỏi ngày 21 tháng 4 năm 2017 trong Midterm
ID: 24269 - Xem được từ: Không giới hạn - Hiệu lực đến: Không giới hạn
| 2.3k đã xem
0 thích 0 k thích
70 trả lời
[Exam] đã hỏi ngày 13 tháng 4 năm 2017 trong Midterm
ID: 23789 - Xem được từ: Không giới hạn - Hiệu lực đến: Không giới hạn
| 8.7k đã xem
0 thích 0 k thích
4 trả lời
[Exam] đã hỏi ngày 21 tháng 4 năm 2017 trong Midterm
ID: 24272 - Xem được từ: Không giới hạn - Hiệu lực đến: Không giới hạn
| 1.2k đã xem
0 thích 0 k thích
11 trả lời
[Exam] đã hỏi ngày 21 tháng 4 năm 2017 trong Midterm
ID: 24270 - Xem được từ: Không giới hạn - Hiệu lực đến: Không giới hạn
| 2.3k đã xem
12,783 câu hỏi
183,442 trả lời
172,219 bình luận
4,824 thành viên