#include <stdio.h> #include <string.h> #define MAX_STUDENT_NUM 30 // #define MAX_COURSE_NUM 6 // #define NAME_LEN 20 // struct Student { char id[10];//学生学号 char name[NAME_LEN];//姓名 int scores[MAX_COURSE_NUM];//各科分数 int total_score;//总分 float avg_score;//平均分 }; void sort_by_name(struct Student students[], int num);//按姓名的字典顺序排出成绩表 void search_by_number(struct Student students[], int num);//按学号查询学生排名极其考试成绩 void search_by_name(struct Student students[], int num);//按姓名查询学生排名极其考试成绩 请用c语言分别补充函数内容
时间: 2023-12-16 10:04:03 浏览: 65
SeqList.h #include <stdio.h> //包含标准输入输出流的头文件 #include <assert.h
好的,下面是三个函数的补充内容:
1. 按姓名的字典顺序排出成绩表
```
void sort_by_name(struct Student students[], int num)
{
int i, j;
for (i = 0; i < num - 1; i++) {
for (j = 0; j < num - i - 1; j++) {
if (strcmp(students[j].name, students[j+1].name) > 0) {
struct Student temp = students[j];
students[j] = students[j+1];
students[j+1] = temp;
}
}
}
}
```
2. 按学号查询学生排名及其考试成绩
```
void search_by_number(struct Student students[], int num)
{
char id[10];
printf("请输入学生学号:");
scanf("%s", id);
int i, rank = -1;
for (i = 0; i < num; i++) {
if (strcmp(students[i].id, id) == 0) {
rank = i + 1;
printf("学号:%s, 姓名:%s, 总分:%d, 平均分:%.2f, 名次:%d\n",
students[i].id, students[i].name, students[i].total_score, students[i].avg_score, rank);
break;
}
}
if (rank == -1) {
printf("未找到该学号对应的学生。\n");
}
}
```
3. 按姓名查询学生排名及其考试成绩
```
void search_by_name(struct Student students[], int num)
{
char name[NAME_LEN];
printf("请输入学生姓名:");
scanf("%s", name);
int i, rank = -1;
for (i = 0; i < num; i++) {
if (strcmp(students[i].name, name) == 0) {
rank = i + 1;
printf("学号:%s, 姓名:%s, 总分:%d, 平均分:%.2f, 名次:%d\n",
students[i].id, students[i].name, students[i].total_score, students[i].avg_score, rank);
break;
}
}
if (rank == -1) {
printf("未找到该姓名对应的学生。\n");
}
}
```
这些函数的实现也可能需要根据具体的需求进行修改和优化。
阅读全文