Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - C language programming programming questions: Please: Complete the requirements for student-related information: 1. Define a structure type student, which includes three components
C language programming programming questions: Please: Complete the requirements for student-related information: 1. Define a structure type student, which includes three components

#include

#include

#define STU_NUM 10 /*Macro defines the number of students*/

struct student /*Define a structure to store the student's student ID, three course grades, total score and average grade*/

{

char stu_id[ 20]; /*Student ID number;*/

float score[3]; /*Three course scores;*/

float total; /*Total score;*/

float aver; /*average grade;*/

};

/*sorting is implemented using a function*/

void SortScore(student *stu,int n)

{

student stud;

for(int i = 0; i < n-1; i++)

for(int j = i+1; j < n; j++)

{

if(stu[i].total < stu[j] .total)

{

stud = stu[i];

stu[i] = stu[j];

stu [j] = stud;

}

}

}

int main( )

{< /p>

student stu[STU_NUM]; /*There are 10 elements in the created structure array, which are used to save the relevant information of these 10 people.

*/

/*Enter relevant information of these ten students*/

for(int i = 0; i

{< /p>

printf("Please enter the student number of the %d student:",i+1);

scanf("%s",&stu[i].stu_id);< /p>

printf("Enter the math score of the %d student:",i+1);

scanf("%f",&stu[i].score[0]) ;

printf("Enter the English score of the %d student:",i+1);

scanf("%f",&stu[i].score[1 ]);

printf("Enter the computer score of the %d student:",i+1);

scanf("%f",&stu[i].score [2]);

stu[i].total = stu[i].score[0]+stu[i].score[1]+stu[i].score[2];< /p>

stu[i].aver = stu[i].total/3;

}

printf("\n");

< p>SortScore(stu,STU_NUM);/*Call the sorting function*/

/*Output the sorted scores of each student*/

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

{

printf("Serial number: %d\t",i);

printf("Student number: %s\t ",stu[i].stu_id);

printf("Mathematics: %f\t",stu[i].score[0]);

printf("English :%f\t",stu[i].score[1]);

printf("Computer: %f\t",stu[i].score[2]);

printf("Average score: %f\t",stu[i].aver);

printf("Total score: %f\t",stu[i].total) ;

printf("\n\n");

}

return 0;

}

Note: (Explanation of the meaning of the main identifiers in the source program)

#define STU_NUM 10 /*Macro defines the number of students*/

struct student /*Define a structure for Store student ID number, three course scores, total score and average grade*/

{

char stu_id[20]; /*Student ID number;*/

float score[3]; /*Three course scores;*/

float total; /*Total score;*/

float aver; /*Average score; */

}