给这段代码添加中文注释:#include<stdio.h> #include<conio.h> #include<windows.h> struct student { char code[10]; float s1,s2,s3; float score; char grade; }temp; void set(int *choice) { printf(" ******* 1、从文件读取数据 *******\n"); printf(" ******* 2、计算并显示成绩 *******\n"); printf(" ******* 3、按等级查询 *******\n"); printf(" ******* 4、按总评成绩排序 *******\n"); printf(" ******* 5、按学号查询 *******\n"); printf(" ******* 6、查询所有等级 *******\n"); printf(" ******* 7、保存到文件 *******\n"); printf(" ******* 0、退出系统 *******\n\n"); printf("请选择您所需要操作的功能:"); *choice=getch(); } void dispinfo() { system("cls"); printf("\n\n"); printf(" *********************** 欢迎成绩核算系统 **********************\n\n"); printf(" *********************** **************** **********************\n\n"); } int duqu(struct student *list) { int n = 0; FILE fp = fopen("C:\Users\dell\Desktop\软件设计-源文件\A3\note.txt", "r"); if (fp == NULL) { printf("无法打开文件"); return n; } char line[100]; fgets(line, 100, fp); sscanf(line, "%d", &n); printf("\n"); // 空一行 printf(" 学号 平时成绩 期中成绩 期末成绩 \n"); // 输出表头 for (int i = 0; i < n; i++) { fgets(line, 100, fp); sscanf(line, "%s %f %f %f", list[i].code, &list[i].s1, &list[i].s2, &list[i].s3); printf("\t %s %5.1lf %5.1lf %5.1lf \n", list[i].code, list[i].s1, list[i].s2, list[i].s3); } printf("\n\n\n ****** 读取文件成功! 按任意键继续! ****** \n"); fclose(fp); while (getchar() != '\n'); // 等待用户按下回车键继续 return n; } void view(struct student list, int amount) { float sum = 0, average = 0; printf("\n 学号 总评 等级 \n"); for (int i = 0; i < amount; i++) { sum += list[i].score; printf("%10s %6.1f %c \n", list[i].code, list[i].score, list[i].grade); } average = sum / amount; printf(" 本班总人数 %d 本班平均成绩 %.1f\n", amount, average); printf("\n\n\n\n\n ***** 摁任意键继续! ****** \n"); getch(); } void paixu(struct student list, int amount) { for (int i = 0; i < amount; i++) { for (int j = i + 1; j < amount; j++) { if (list[j].score > list[i].score) { struct student temp = list[j]; list[j] = list[i]; list[i] = temp; } } } view(list, amount); } void calculate(struct student list[], int amount) { for(int i = 0; i < amount; i++) { float score = list[i].s10.3 + list[i].s20.3 + list[i].s30.4; list[i].score = score; if(score >= 90) { list[i].grade = 'A'; } else if(score >= 80) { list[i].grade = 'B'; } else if(score >= 70) { list[i].grade = 'C'; } else if(score >= 60) { list[i].grade = 'D'; } else { list[i].grade = 'E'; } } dispinfo(); view(list, amount); }
时间: 2023-07-19 22:56:39 浏览: 108
// 引入头文件
#include<stdio.h>
#include<conio.h>
#include<windows.h>
// 定义学生结构体
struct student {
char code[10]; // 学号
float s1,s2,s3; // 平时成绩,期中成绩,期末成绩
float score; // 总评成绩
char grade; // 成绩等级
}temp;
// 设置函数,用于选择功能
void set(int *choice) {
printf(" ******* 1、从文件读取数据 *******\n");
printf(" ******* 2、计算并显示成绩 *******\n");
printf(" ******* 3、按等级查询 *******\n");
printf(" ******* 4、按总评成绩排序 *******\n");
printf(" ******* 5、按学号查询 *******\n");
printf(" ******* 6、查询所有等级 *******\n");
printf(" ******* 7、保存到文件 *******\n");
printf(" ******* 0、退出系统 *******\n\n");
printf("请选择您所需要操作的功能:");
*choice=getch();
}
// 显示信息函数
void dispinfo() {
system("cls"); // 清屏
printf("\n\n");
printf(" *********************** 欢迎成绩核算系统 **********************\n\n");
printf(" *********************** **************** **********************\n\n");
}
// 读取文件函数
int duqu(struct student *list) {
int n = 0;
FILE fp = fopen("C:\Users\dell\Desktop\软件设计-源文件\A3\note.txt", "r"); // 打开文件
if (fp == NULL) { // 判断文件是否能够打开
printf("无法打开文件");
return n;
}
char line[100]; // 定义一个字符数组
fgets(line, 100, fp); // 读取一行
sscanf(line, "%d", &n); // 从字符串中读取一个整数
printf("\n"); // 空一行
printf(" 学号 平时成绩 期中成绩 期末成绩 \n"); // 输出表头
for (int i = 0; i < n; i++) { // 循环读取每个学生的信息
fgets(line, 100, fp); // 读取一行
sscanf(line, "%s %f %f %f", list[i].code, &list[i].s1, &list[i].s2, &list[i].s3); // 从字符串中读取学生的学号和成绩
printf("\t %s %5.1lf %5.1lf %5.1lf \n", list[i].code, list[i].s1, list[i].s2, list[i].s3); // 输出学生的成绩
}
printf("\n\n\n ****** 读取文件成功! 按任意键继续! ****** \n");
fclose(fp); // 关闭文件
while (getchar() != '\n'); // 等待用户按下回车键继续
return n;
}
// 显示学生成绩函数
void view(struct student list, int amount) {
float sum = 0, average = 0;
printf("\n 学号 总评 等级 \n");
for (int i = 0; i < amount; i++) {
sum += list[i].score;
printf("%10s %6.1f %c \n", list[i].code, list[i].score, list[i].grade);
}
average = sum / amount; // 计算平均成绩
printf(" 本班总人数 %d 本班平均成绩 %.1f\n", amount, average);
printf("\n\n\n\n\n ***** 摁任意键继续! ****** \n");
getch();
}
// 按总评成绩排序函数
void paixu(struct student list, int amount) {
for (int i = 0; i < amount; i++) {
for (int j = i + 1; j < amount; j++) {
if (list[j].score > list[i].score) {
struct student temp = list[j];
list[j] = list[i];
list[i] = temp;
}
}
}
view(list, amount); // 显示学生成绩
}
// 计算并显示成绩函数
void calculate(struct student list[], int amount) {
for(int i = 0; i < amount; i++) {
float score = list[i].s10.3 + list[i].s20.3 + list[i].s30.4; // 计算总评成绩
list[i].score = score; // 将总评成绩赋值给结构体中的score变量
if(score >= 90) { // 判断成绩等级
list[i].grade = 'A';
} else if(score >= 80) {
list[i].grade = 'B';
} else if(score >= 70) {
list[i].grade = 'C';
} else if(score >= 60) {
list[i].grade = 'D';
} else {
list[i].grade = 'E';
}
}
dispinfo(); // 显示信息
view(list, amount); // 显示学生成绩
}
相关推荐
![text/x-c](https://img-home.csdnimg.cn/images/20210720083646.png)
![image/gif](https://img-home.csdnimg.cn/images/20210720083352.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)