#include <stdio.h> #include <string.h> #define MAX_STUDENT_NUM 30 //最大学生个数 #define MAX_COURSE_NUM 6 //最大课程个数 #define NAME_LEN 20 //最大名字个数 typedef struct Student { char id[10];//学生学号 char name[NAME_LEN];//姓名 int scores[MAX_COURSE_NUM];//各科分数 int total_score;//总分 float avg_score;//平均分 } XUESHENG;//将结构体名称命名为XUESHENG void sort_by_total_score(XUESHENG students[], int num);//按每个学生的总分由高到低排出名次表 void sort_by_number(XUESHENG students[], int num);//按学号由小到大排出成绩表 void sort_by_name(XUESHENG students[], int num);//按姓名的字典顺序排出成绩表 请补充各个函数
时间: 2024-01-16 12:01:52 浏览: 105
函数1:按每个学生的总分由高到低排出名次表
```
void sort_by_total_score(XUESHENG students[], int num){
int i, j;
XUESHENG temp;
for(i = 0; i < num - 1; i++){
for(j = i + 1; j < num; j++){
if(students[i].total_score < students[j].total_score){
temp = students[i];
students[i] = students[j];
students[j] = temp;
}
}
}
}
```
函数2:按学号由小到大排出成绩表
```
void sort_by_number(XUESHENG students[], int num){
int i, j;
XUESHENG temp;
for(i = 0; i < num - 1; i++){
for(j = i + 1; j < num; j++){
if(strcmp(students[i].id, students[j].id) > 0){
temp = students[i];
students[i] = students[j];
students[j] = temp;
}
}
}
}
```
函数3:按姓名的字典顺序排出成绩表
```
void sort_by_name(XUESHENG students[], int num){
int i, j;
XUESHENG temp;
for(i = 0; i < num - 1; i++){
for(j = i + 1; j < num; j++){
if(strcmp(students[i].name, students[j].name) > 0){
temp = students[i];
students[i] = students[j];
students[j] = temp;
}
}
}
}
```
阅读全文