From 871b59b7f0aadd04ce770c2d4a27cd8b57bdc571 Mon Sep 17 00:00:00 2001 From: tong tong zhang Date: Tue, 25 Apr 2023 16:24:48 +0800 Subject: [PATCH] 111 --- readme1.md | 641 ----------------------------------------------------- readme2.md | 641 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 641 insertions(+), 641 deletions(-) create mode 100644 readme2.md diff --git a/readme1.md b/readme1.md index 36caef0..e69de29 100644 --- a/readme1.md +++ b/readme1.md @@ -1,641 +0,0 @@ -#学生成绩管理系统 -2023年4月16日 - -组长:张桐桐 -组员:孟婷玉 李玉璇 周羽凡 - -下载地址:https://code.educoder.net/pn8rjlxip/System#readme - -## 项目简介 -本学生成绩管理系统是为教师提供管理班级成绩的工具,该系统可以实现的对学生的成绩进行增、删、改、查、信息保存和信息导入等基本功能,以及对学生成绩排序和分段的扩展功能,有利于对学生成绩管理。 - -项目开发过程中采用 Kanban(看板)进行任务管理和分工协作,并使用 Git 对程序代码和文档进行版本管理。任务分工情况如下: - -| 任务 | 设计 | 开发 | 测试 | 文档 | -| ---- | ---- | ---- | ---- | ---- | -| C1-C3 菜单驱动的用户界面 |张桐桐| 张桐桐 | 李玉璇 | 张桐桐 | -| C4 添加学生信息 | 成员2 | 成员2 | 成员3 | 成员2 | -|C5-C6 求和求平均 | ... | ... | ... | ... | -|C7-C9 排序 | ... | ... | ... | ... | -| C10 学生信息查询 | ... | ... | ... | ... | -|C11 统计学生信息| ... | ... | ... | ... | -|C12 打印学生信息 | ... | ... | ... | ... | -| C13 将学生信息读入文件| 成员1 | 成员1 | 成员2,成员3 | 成员1 | -| C14 从文件中读取学生信息 | 成员2 | 成员2 | 成员3 | 成员2 | - -每个成员的工作量(百分比): - -| 张桐桐 | 李玉璇 | 周羽凡 |孟婷玉| -| ---- | ---- | ---- |----| -| 3 | | | | - - - -关于学生成绩管理系统 -设计一个学生成绩管理系统,要求采用行菜单界面进行交互,具备读取、保存、打印、查询、插入和排序等基本功能,能够以表格和图表形式展示数据,采用CSV格式保存数据。 - -系统的功能性需求: - -数据的读取、保存、打印、查询、插入、排序和图表展示。 -系统的非功能性需求: - -菜单驱动的命令行交互界面 -需求分析 -分析系统的功能需求和界面需求,编制用户手册如下。 - -C1: 启动程序 -命令行中执行命令./app,系统启动,显示提示信息,然后显示功能菜单,等待用户输入命令。 -```` -Management for Students'scores -1 Input record -2 Calculate total and average score of every course -3 Calculate total and average score of every student -4 Sort in descending order by score -5 Sort in ascending order by score -6 Sort in ascending order by number -7 Sort in dictionary order by name -8 Search by number -9 Search by name -10 Statistic analysis -11 List record -12 Write to a file -13 Read from a file -0 Exit -Please Input your choice: -```` -C2: 显示命令菜单 -调用 Menu() 函数显示命令菜单,用户输入选项后,将结果返回主函数 -```` -Management for Students'scores -1 Input record -2 Calculate total and average score of every course -3 Calculate total and average score of every student -4 Sort in descending order by score -5 Sort in ascending order by score -6 Sort in ascending order by number -7 Sort in dictionary order by name -8 Search by number -9 Search by name -10 Statistic analysis -11 List record -12 Write to a file -13 Read from a file -0 Exit -Please Input your choice: -```` -C3: 退出程序 -选择菜单命令 0 ,再输入 y 确认,则退出程序。 -```` -请输入你的选择: 0 -你确定你想进入吗?(确定/不确定): 确定 -结束程序! -```` - - - - - - - - - - - - -C6: 计算每门课程的总分和平均分 -选择菜单命令 3 ,计算每门课程的总分和平均分,然后利用循环逐个输出每门课程的总分和平均分,结果都取整数。 -```` -Please Input your choice: 3 -course 1: sum = 337, aver = 84 -course 2: sum = 364, aver = 91 -course 3: sum = 383, aver = 95 -```` -C7: 学生总分排序 -如果a < b,则按升序排列。选择菜单命令 4 ,按选择法将数组 sum 的元素值按升序进行排序,显示提示信息,最后打印出学生信息。 -如果a > b,则按降序排序。选择菜单命令 5 ,按选择法将数组 sum 的元素值按降序进行排序,显示提示信息,最后打印出学生成绩。 -```` -Please Input your choice: 4 -Sort in descending order by score: -2214111006 XuZilin 100 95 86 281 93 -2214111011 ZhangYu 85 91 98 274 91 -2214111009 XuZigui 77 89 99 265 88 -2214111025 LiYujia 75 89 100 264 88 -Please Input your choice: 5 -Sort in ascending order by score: -2214111025 LiYujia 75 89 100 264 88 -2214111009 XuZigui 77 89 99 265 88 -2214111011 ZhangYu 85 91 98 274 91 -2214111006 XuZilin 100 95 86 281 93 -```` -C8: 学号顺序排序 -选择菜单命令 6 ,按学号从小到大进行排序,显示提示信息,最后打印学生信息。 -```` -Please Input your choice: 6 -Sort in ascending order by number: -2214111006 XuZilin 100 95 86 281 93 -2214111009 XuZigui 77 89 99 265 88 -2214111011 ZhangYu 85 91 98 274 91 -2214111025 LiYujia 75 89 100 264 88 -```` -C9: 姓名顺序排序 -选择菜单命令 7 ,按姓名的字典顺序进行排序,显示提示信息,最后打印学生信息。 -```` -Please Input your choice: 7 -Sort in dictionary order by name: -2214111025 LiYujia 75 89 100 264 88 -2214111009 XuZigui 77 89 99 265 88 -2214111006 XuZilin 100 95 86 281 93 -2214111011 ZhangYu 85 91 98 274 91 -```` -C10: 学生信息查询 -选择菜单命令 8 ,提示输入学生学号,若该学号存在,则输出学生信息;否则提示没有找到并结束。 -```` -Please Input your choice: 8 -Input the number you want to search:2214111011 -2214111011 ZhangYu 85 91 98 274 91 -1 Input record -2 Calculate total and average score of every course -3 Calculate total and average score of every student -4 Sort in descending order by score -5 Sort in ascending order by score -6 Sort in ascending order by number -7 Sort in dictionary order by name -8 Search by number -9 Search by name -10 Statistic analysis -11 List record -12 Write to a file -13 Read from a file -0 Exit -Please Input your choice: 8 -Input the number you want to search:2214111001 -Not found! -选择菜单命令 9 ,提示输入学生姓名,若该姓名存在,则输出学生信息;否则提示没有找到并结束。 -Please Input your choice: 9 -Input the name you want to search:LiYujia -2214111025 LiYujia 75 89 100 264 88 -1 Input record -2 Calculate total and average score of every course -3 Calculate total and average score of every student -4 Sort in descending order by score -5 Sort in ascending order by score -6 Sort in ascending order by number -7 Sort in dictionary order by name -8 Search by number -9 Search by name -10 Statistic analysis -11 List record -12 Write to a file -13 Read from a file -0 Exit -Please Input your choice: 9 -Input the name you want to search:SunYizhe -Not found! -```` -C11: 统计各分数段学生人数及所占百分比 -选择菜单命令 10,提示输入学生成绩,通过循环得出各分数段学生人数及所占百分比 -```` -Please Input your choice: 10 -For course 1: -<60 0 0.00% -60-70 0 0.00% -70-80 2 50.00% -80-90 1 25.00% -90-100 0 0.00% -100 1 25.00% -For course 2: -<60 0 0.00% -60-70 0 0.00% -70-80 0 00.00% -80-90 2 50.00% -90-100 2 50.00% -100 0 0.00% -For course 3: -<60 0 0.00% -60-70 0 0.00% -70-80 0 0.00% -80-90 1 25.00% -90-100 2 50.00% -100 1 25.00% -```` -C12: 打印学生信息 -选择菜单命令11,打印 -```` -Please Input your choice: 11 -2214111006 XuZilin 100 95 86 281 93 -2214111009 XuZigui 77 89 99 265 88 -2214111011 ZhangYu 85 91 98 274 91 -2214111025 LiYujia 75 89 100 264 88 -```` -C13: 将学生信息保存在文件中 -选择菜单命令 12 ,将学生信息保存在文件 student.txt 中。如果文件不存在,则给出错误信息并退出程序,否则逐个读入 -```` -Please Input your choice: 12 -Failure to open score.txt! -1 Input record -2 Calculate total and average score of every course -3 Calculate total and average score of every student -4 Sort in descending order by score -5 Sort in ascending order by score -6 Sort in ascending order by number -7 Sort in dictionary order by name -8 Search by number -9 Search by name -10 Statistic analysis -11 List record -12 Write to a file -13 Read from a file -0 Exit -Please Input your choice: 12 -2214111006 XuZilin 100 95 86 281 93 -2214111009 XuZigui 77 89 99 265 88 -2214111011 ZhangYu 85 91 98 274 91 -2214111025 LiYujia 75 89 100 264 88 -```` -C14:从文件中读取学生信息 -选择菜单命令 13 ,从文件中读取学生的学号、姓名及成绩等信息写入到结构体数组 stu 中。如果文件为空,则给出错误信息并退出程序,反之,逐个读入 -```` -Please Input your choice: 13 -Failure to open score.txt! -1 Input record -2 Calculate total and average score of every course -3 Calculate total and average score of every student -4 Sort in descending order by score -5 Sort in ascending order by score -6 Sort in ascending order by number -7 Sort in dictionary order by name -8 Search by number -9 Search by name -10 Statistic analysis -11 List record -12 Write to a file -13 Read from a file -0 Exit -Please Input your choice: 13 -2214111006 XuZilin 100 95 86 281 93 -2214111009 XuZigui 77 89 99 265 88 -2214111011 ZhangYu 85 91 98 274 91 -2214111025 LiYujia 75 89 100 264 88 -```` -概要设计 -系统主要分为用户界面和数据处理两大模块。 -用户界面模块包括系统初始化(init),显示菜单(display_menu),选择菜单命令(make_choice)、确认(confirm)、退出(quit)等子模块。 -数据处理模块包括读取数据(read_data)、保存数据(save_data)、打印数据(print_data)、查询数据(query_data)、添加数据(add_data)、更新数据(update_data)、删除数据(delete_data)、数据排序(sort_data)和生成图表(make_chart)等子模块。其中查询、添加、更 -新和删除数据还会用到根据编号查询数据的方法(find)。 - -上述各模块通过主程序(main)进行调用,系统模块图如下。 - -![添加库存记录流程图](test.drawio.svg) - -各模块的主要功能如下: - -main -系统主函数模块,显示菜单,根据用户选择的菜单命令,执行相关操作。 - -init -系统初始化 - -menu -显示菜单命令 - -详细设计 -针对概要设计 - -main -Step 1:初始化 -Step 2:根据用户选择的命令执行相应的操作 -Step 2.1:显示菜单 -Step 2.2:选择菜单命令 c -Step 2.3:if c == 1 then ReadScore -Step 2.4:if c == 2 then AverSumofEveryStudent -Step 2.5:if c == 3 then AverSumofEveryCourse -Step 2.6:if c == 4 then SortbyScore(Descending) -Step 2.7:if c == 5 then SortbyScore(Ascending) -Step 2.8:if c == 6 then AsSortbyNum -Step 2.9:if c == 7 then SortbyName -Step 2.10:if c == 8 then SearchbyNum -Step 2.11:if c == 9 then SearchbyName -Step 2.12:if c == 10 then StatisticAnalysis -Step 2.13:if c == 11 then PrintScore -Step 2.14:if c == 12 then WritetoFile -Step 2.15:if c == 13 then ReadfromFile -Step 2.16:if c == 0 then exit - -系统模块图 - -ReadScore -Step 1:显示提示信息,要求输入学生的学号,姓名和成绩 -Step 2:利用循环,输入学生的学号,成绩和各科成绩 - -学生信息输入 - -AverSumofEveryStudent -Step 1:利用for循环给 sum 赋初值为 0 -Step 2:利用第二重循环重新计算每个学生的总分 -Step 3:计算每个学生的平均分 -Step 4:将结果按照舒徐,总分和平均分的顺序进行输出 - -计算每个学生各门课程的总分和平均分 - -AverSumofEveryCourse -SortbyScore -SortbyScore -AsSortbyNum -SortbyName -SearchbyNum -SearchbyName -StatisticAnalysis -PrintScore -WritetoFile -ReadfromFile -exit - -代码实现 -// 头文件的使用 - -下面是代码库 -````c - -#include -#include -#include -#define MAX_LEN 10 // 字符串最大长度 -#define STU_NUM 30 // 最多的学生人数 -#define COURSE_NUM 6 // 最多的考试科目数 -typedef struct student -{ - long num; // 每个学生的学号 - char name[MAX_LEN]; // 每个学生的姓名 - float score[COURSE_NUM]; // 每个学生COURSE_NUM门功课的成绩 - float sum; // 每个学生的总成绩 - float aver; // 每个学生的平均成绩 -}STU; -int Menu(void); -void ReadScore(STU stu[], int n, int m); -void AverSumofEveryStudent(STU stu[], int n, int m); -void AverSumofEveryCourse(STU stu[], int n, int m); -void SortbyScore(STU stu[],int n,int m,int (*compare)(float a,float b)); -int Ascending(float a, float b); -int Descending(float a, float b); -void SwapFloat(float *x, float *y); -void SwapLong(long *x, long *y); -void SwapChar(char x[], char y[]); -void AsSortbyNum(STU stu[], int n, int m); -void SortbyName(STU stu[], int n, int m); -void SearchbyNum(STU stu[], int n, int m); -void SearchbyName(STU stu[], int n, int m); -void StatisticAnalysis(STU stu[], int n, int m); -void PrintScore(STU stu[], int n, int m); -void WritetoFile(STU record[], int n, int m); -void ReadfromFile(STU record[], int *n, int *m); -int main(void) -{ - char ch; - int n = 0, m = 0; - STU stu[STU_NUM]; -printf("Input student number(n<%d):", STU_NUM); - scanf("%d", &n); -printf("Input course number(m<=%d):",COURSE_NUM); - scanf("%d", &m); - while (1) - { - ch = Menu(); // 显示菜单,并读取用户输入 - switch (ch) - { - case 1:ReadScore(stu, n, m); - break; - case 2: AverSumofEveryCourse(stu, n, m); - break; - case 3: AverSumofEveryStudent(stu, n, m); - break; - case 4: SortbyScore(stu, n, m, Descending); - printf("\nSort in descending order by score:\n"); - PrintScore(stu, n, m); - break; - case 5: SortbyScore(stu, n, m, Ascending); - printf("\nSort in ascending order by score:\n"); - PrintScore(stu, n, m); - break; - case 6: AsSortbyNum(stu, n, m); - printf("\nSort in ascending order by number:\n"); - PrintScore(stu, n, m); - break; - case 7: SortbyName(stu, n, m); - printf("\nSort in dictionary order by name:\n"); - PrintScore(stu, n, m); - break; - case 8: SearchbyNum(stu, n, m); - break; - case 9: SearchbyName(stu, n, m); - break; - case 10: StatisticAnalysis(stu, n, m); - break; - case 11:PrintScore(stu, n, m); - break; -case 12:WritetoFile(stu, n, m); - break; - case 13:ReadfromFile(stu, &n, &m); - break; - case 0: printf("End of program!"); - exit(0); - default:printf("Input error!"); - } - } - return 0;} -// 函数功能:显示菜单并获得用户键盘输入的选项 -int Menu(void) -{ - int itemSelected; - printf("Management for Students' scores\n"); - printf("1.Input record\n"); - printf("2.Calculate total and average score of every course\n"); - printf("3.Calculate total and average score of every student\n"); - printf("4.Sort in descending order by score\n"); - printf("5.Sort in ascending order by score\n"); - printf("6.Sort in ascending order by number\n"); - printf("7.Sort in dictionary order by name\n"); - printf("8.Search by number\n"); - printf("9.Search by name\n"); - printf("10.Statistic analysis\n"); - printf("11.List record\n"); - printf("12.Write to a file\n"); - printf("13.Read from a file\n"); - printf("0.Exit\n"); - printf("Please Input your choice:"); - scanf("%d", &itemSelected); // 读入用户输入 - return itemSelected; -} -//1 函数功能:输入n个学生的m门课成绩 -void ReadScore(STU stu[], int n, int m) -{ - int i, j; - printf("Input student's ID, name and score:\n"); - for(i=0;i0 ? stu[i].sum / m : -1; - printf("student %d: sum = %.0f, aver = %.0f\n", -i+1, stu[i].sum, stu[i].aver); - } -} -//3 函数功能:计算每门课程的总分和平均分 - -//4 函数功能:按选择法将数组sum的元素值排序 - -// 5使数据按升序排序 -int Ascending(float a, float b) -{ - return a < b; // 这样比较决定了按升序排序,如果a b; -} -// 7交换两个单精度浮点型数据 - -// 8交换两个长整型数据 - -// 9交换两个字符串 -void SwapChar(char x[], char y[]) -{ -char temp[MAX_LEN]; -strcpy(temp, x); -strcpy(x, y); -strcpy(y, temp); -} -// 10函数功能:按选择法将数组num的元素值按从低到高排序 - -// 11函数功能:交换法实现字符串按字典顺序排序 -void AsSortbyNum(STU stu[], int n, int m) -{ - int i, j, k, t; - for (i=0; i=0 && stu[i].score[j]<60)t[0]++; - else if (stu[i].score[j]<70) t[1]++; - else if (stu[i].score[j]<80) t[2]++; - else if (stu[i].score[j]<90) t[3]++; - else if (stu[i].score[j]<100) t[4]++; - else if (stu[i].score[j] == 100) t[5]++; - } - for (i=0; i<=5; i++) - { - if (i==0) printf("<60\t%d\t%.2f%%\n",t[i],(float)t[i]/n*100); - else if (i==5) printf("%d\t%d\t%.2f%%\n", -(i+5)*10,t[i],(float)t[i]/n*100); - else printf("%d-%d\t%d\t%.2f%%\n", -(i+5)*10, (i+5)*10+9, t[i], (float)t[i]/n*100); - } - } -} - -// 15函数功能: 打印学生成绩 -void PrintScore(STU stu[], int n, int m) -{ - int i, j; - for (i=0; i b,则按降序排序。选择菜单命令 5 ,按选择法将数组 sum 的元素值按降序进行排序,显示提示信息,最后打印出学生成绩。 +```` +Please Input your choice: 4 +Sort in descending order by score: +2214111006 XuZilin 100 95 86 281 93 +2214111011 ZhangYu 85 91 98 274 91 +2214111009 XuZigui 77 89 99 265 88 +2214111025 LiYujia 75 89 100 264 88 +Please Input your choice: 5 +Sort in ascending order by score: +2214111025 LiYujia 75 89 100 264 88 +2214111009 XuZigui 77 89 99 265 88 +2214111011 ZhangYu 85 91 98 274 91 +2214111006 XuZilin 100 95 86 281 93 +```` +C8: 学号顺序排序 +选择菜单命令 6 ,按学号从小到大进行排序,显示提示信息,最后打印学生信息。 +```` +Please Input your choice: 6 +Sort in ascending order by number: +2214111006 XuZilin 100 95 86 281 93 +2214111009 XuZigui 77 89 99 265 88 +2214111011 ZhangYu 85 91 98 274 91 +2214111025 LiYujia 75 89 100 264 88 +```` +C9: 姓名顺序排序 +选择菜单命令 7 ,按姓名的字典顺序进行排序,显示提示信息,最后打印学生信息。 +```` +Please Input your choice: 7 +Sort in dictionary order by name: +2214111025 LiYujia 75 89 100 264 88 +2214111009 XuZigui 77 89 99 265 88 +2214111006 XuZilin 100 95 86 281 93 +2214111011 ZhangYu 85 91 98 274 91 +```` +C10: 学生信息查询 +选择菜单命令 8 ,提示输入学生学号,若该学号存在,则输出学生信息;否则提示没有找到并结束。 +```` +Please Input your choice: 8 +Input the number you want to search:2214111011 +2214111011 ZhangYu 85 91 98 274 91 +1 Input record +2 Calculate total and average score of every course +3 Calculate total and average score of every student +4 Sort in descending order by score +5 Sort in ascending order by score +6 Sort in ascending order by number +7 Sort in dictionary order by name +8 Search by number +9 Search by name +10 Statistic analysis +11 List record +12 Write to a file +13 Read from a file +0 Exit +Please Input your choice: 8 +Input the number you want to search:2214111001 +Not found! +选择菜单命令 9 ,提示输入学生姓名,若该姓名存在,则输出学生信息;否则提示没有找到并结束。 +Please Input your choice: 9 +Input the name you want to search:LiYujia +2214111025 LiYujia 75 89 100 264 88 +1 Input record +2 Calculate total and average score of every course +3 Calculate total and average score of every student +4 Sort in descending order by score +5 Sort in ascending order by score +6 Sort in ascending order by number +7 Sort in dictionary order by name +8 Search by number +9 Search by name +10 Statistic analysis +11 List record +12 Write to a file +13 Read from a file +0 Exit +Please Input your choice: 9 +Input the name you want to search:SunYizhe +Not found! +```` +C11: 统计各分数段学生人数及所占百分比 +选择菜单命令 10,提示输入学生成绩,通过循环得出各分数段学生人数及所占百分比 +```` +Please Input your choice: 10 +For course 1: +<60 0 0.00% +60-70 0 0.00% +70-80 2 50.00% +80-90 1 25.00% +90-100 0 0.00% +100 1 25.00% +For course 2: +<60 0 0.00% +60-70 0 0.00% +70-80 0 00.00% +80-90 2 50.00% +90-100 2 50.00% +100 0 0.00% +For course 3: +<60 0 0.00% +60-70 0 0.00% +70-80 0 0.00% +80-90 1 25.00% +90-100 2 50.00% +100 1 25.00% +```` +C12: 打印学生信息 +选择菜单命令11,打印 +```` +Please Input your choice: 11 +2214111006 XuZilin 100 95 86 281 93 +2214111009 XuZigui 77 89 99 265 88 +2214111011 ZhangYu 85 91 98 274 91 +2214111025 LiYujia 75 89 100 264 88 +```` +C13: 将学生信息保存在文件中 +选择菜单命令 12 ,将学生信息保存在文件 student.txt 中。如果文件不存在,则给出错误信息并退出程序,否则逐个读入 +```` +Please Input your choice: 12 +Failure to open score.txt! +1 Input record +2 Calculate total and average score of every course +3 Calculate total and average score of every student +4 Sort in descending order by score +5 Sort in ascending order by score +6 Sort in ascending order by number +7 Sort in dictionary order by name +8 Search by number +9 Search by name +10 Statistic analysis +11 List record +12 Write to a file +13 Read from a file +0 Exit +Please Input your choice: 12 +2214111006 XuZilin 100 95 86 281 93 +2214111009 XuZigui 77 89 99 265 88 +2214111011 ZhangYu 85 91 98 274 91 +2214111025 LiYujia 75 89 100 264 88 +```` +C14:从文件中读取学生信息 +选择菜单命令 13 ,从文件中读取学生的学号、姓名及成绩等信息写入到结构体数组 stu 中。如果文件为空,则给出错误信息并退出程序,反之,逐个读入 +```` +Please Input your choice: 13 +Failure to open score.txt! +1 Input record +2 Calculate total and average score of every course +3 Calculate total and average score of every student +4 Sort in descending order by score +5 Sort in ascending order by score +6 Sort in ascending order by number +7 Sort in dictionary order by name +8 Search by number +9 Search by name +10 Statistic analysis +11 List record +12 Write to a file +13 Read from a file +0 Exit +Please Input your choice: 13 +2214111006 XuZilin 100 95 86 281 93 +2214111009 XuZigui 77 89 99 265 88 +2214111011 ZhangYu 85 91 98 274 91 +2214111025 LiYujia 75 89 100 264 88 +```` +概要设计 +系统主要分为用户界面和数据处理两大模块。 +用户界面模块包括系统初始化(init),显示菜单(display_menu),选择菜单命令(make_choice)、确认(confirm)、退出(quit)等子模块。 +数据处理模块包括读取数据(read_data)、保存数据(save_data)、打印数据(print_data)、查询数据(query_data)、添加数据(add_data)、更新数据(update_data)、删除数据(delete_data)、数据排序(sort_data)和生成图表(make_chart)等子模块。其中查询、添加、更 +新和删除数据还会用到根据编号查询数据的方法(find)。 + +上述各模块通过主程序(main)进行调用,系统模块图如下。 + +![添加库存记录流程图](test.drawio.svg) + +各模块的主要功能如下: + +main +系统主函数模块,显示菜单,根据用户选择的菜单命令,执行相关操作。 + +init +系统初始化 + +menu +显示菜单命令 + +详细设计 +针对概要设计 + +main +Step 1:初始化 +Step 2:根据用户选择的命令执行相应的操作 +Step 2.1:显示菜单 +Step 2.2:选择菜单命令 c +Step 2.3:if c == 1 then ReadScore +Step 2.4:if c == 2 then AverSumofEveryStudent +Step 2.5:if c == 3 then AverSumofEveryCourse +Step 2.6:if c == 4 then SortbyScore(Descending) +Step 2.7:if c == 5 then SortbyScore(Ascending) +Step 2.8:if c == 6 then AsSortbyNum +Step 2.9:if c == 7 then SortbyName +Step 2.10:if c == 8 then SearchbyNum +Step 2.11:if c == 9 then SearchbyName +Step 2.12:if c == 10 then StatisticAnalysis +Step 2.13:if c == 11 then PrintScore +Step 2.14:if c == 12 then WritetoFile +Step 2.15:if c == 13 then ReadfromFile +Step 2.16:if c == 0 then exit + +系统模块图 + +ReadScore +Step 1:显示提示信息,要求输入学生的学号,姓名和成绩 +Step 2:利用循环,输入学生的学号,成绩和各科成绩 + +学生信息输入 + +AverSumofEveryStudent +Step 1:利用for循环给 sum 赋初值为 0 +Step 2:利用第二重循环重新计算每个学生的总分 +Step 3:计算每个学生的平均分 +Step 4:将结果按照舒徐,总分和平均分的顺序进行输出 + +计算每个学生各门课程的总分和平均分 + +AverSumofEveryCourse +SortbyScore +SortbyScore +AsSortbyNum +SortbyName +SearchbyNum +SearchbyName +StatisticAnalysis +PrintScore +WritetoFile +ReadfromFile +exit + +代码实现 +// 头文件的使用 + +下面是代码库 +````c + +#include +#include +#include +#define MAX_LEN 10 // 字符串最大长度 +#define STU_NUM 30 // 最多的学生人数 +#define COURSE_NUM 6 // 最多的考试科目数 +typedef struct student +{ + long num; // 每个学生的学号 + char name[MAX_LEN]; // 每个学生的姓名 + float score[COURSE_NUM]; // 每个学生COURSE_NUM门功课的成绩 + float sum; // 每个学生的总成绩 + float aver; // 每个学生的平均成绩 +}STU; +int Menu(void); +void ReadScore(STU stu[], int n, int m); +void AverSumofEveryStudent(STU stu[], int n, int m); +void AverSumofEveryCourse(STU stu[], int n, int m); +void SortbyScore(STU stu[],int n,int m,int (*compare)(float a,float b)); +int Ascending(float a, float b); +int Descending(float a, float b); +void SwapFloat(float *x, float *y); +void SwapLong(long *x, long *y); +void SwapChar(char x[], char y[]); +void AsSortbyNum(STU stu[], int n, int m); +void SortbyName(STU stu[], int n, int m); +void SearchbyNum(STU stu[], int n, int m); +void SearchbyName(STU stu[], int n, int m); +void StatisticAnalysis(STU stu[], int n, int m); +void PrintScore(STU stu[], int n, int m); +void WritetoFile(STU record[], int n, int m); +void ReadfromFile(STU record[], int *n, int *m); +int main(void) +{ + char ch; + int n = 0, m = 0; + STU stu[STU_NUM]; +printf("Input student number(n<%d):", STU_NUM); + scanf("%d", &n); +printf("Input course number(m<=%d):",COURSE_NUM); + scanf("%d", &m); + while (1) + { + ch = Menu(); // 显示菜单,并读取用户输入 + switch (ch) + { + case 1:ReadScore(stu, n, m); + break; + case 2: AverSumofEveryCourse(stu, n, m); + break; + case 3: AverSumofEveryStudent(stu, n, m); + break; + case 4: SortbyScore(stu, n, m, Descending); + printf("\nSort in descending order by score:\n"); + PrintScore(stu, n, m); + break; + case 5: SortbyScore(stu, n, m, Ascending); + printf("\nSort in ascending order by score:\n"); + PrintScore(stu, n, m); + break; + case 6: AsSortbyNum(stu, n, m); + printf("\nSort in ascending order by number:\n"); + PrintScore(stu, n, m); + break; + case 7: SortbyName(stu, n, m); + printf("\nSort in dictionary order by name:\n"); + PrintScore(stu, n, m); + break; + case 8: SearchbyNum(stu, n, m); + break; + case 9: SearchbyName(stu, n, m); + break; + case 10: StatisticAnalysis(stu, n, m); + break; + case 11:PrintScore(stu, n, m); + break; +case 12:WritetoFile(stu, n, m); + break; + case 13:ReadfromFile(stu, &n, &m); + break; + case 0: printf("End of program!"); + exit(0); + default:printf("Input error!"); + } + } + return 0;} +// 函数功能:显示菜单并获得用户键盘输入的选项 +int Menu(void) +{ + int itemSelected; + printf("Management for Students' scores\n"); + printf("1.Input record\n"); + printf("2.Calculate total and average score of every course\n"); + printf("3.Calculate total and average score of every student\n"); + printf("4.Sort in descending order by score\n"); + printf("5.Sort in ascending order by score\n"); + printf("6.Sort in ascending order by number\n"); + printf("7.Sort in dictionary order by name\n"); + printf("8.Search by number\n"); + printf("9.Search by name\n"); + printf("10.Statistic analysis\n"); + printf("11.List record\n"); + printf("12.Write to a file\n"); + printf("13.Read from a file\n"); + printf("0.Exit\n"); + printf("Please Input your choice:"); + scanf("%d", &itemSelected); // 读入用户输入 + return itemSelected; +} +//1 函数功能:输入n个学生的m门课成绩 +void ReadScore(STU stu[], int n, int m) +{ + int i, j; + printf("Input student's ID, name and score:\n"); + for(i=0;i0 ? stu[i].sum / m : -1; + printf("student %d: sum = %.0f, aver = %.0f\n", +i+1, stu[i].sum, stu[i].aver); + } +} +//3 函数功能:计算每门课程的总分和平均分 + +//4 函数功能:按选择法将数组sum的元素值排序 + +// 5使数据按升序排序 +int Ascending(float a, float b) +{ + return a < b; // 这样比较决定了按升序排序,如果a b; +} +// 7交换两个单精度浮点型数据 + +// 8交换两个长整型数据 + +// 9交换两个字符串 +void SwapChar(char x[], char y[]) +{ +char temp[MAX_LEN]; +strcpy(temp, x); +strcpy(x, y); +strcpy(y, temp); +} +// 10函数功能:按选择法将数组num的元素值按从低到高排序 + +// 11函数功能:交换法实现字符串按字典顺序排序 +void AsSortbyNum(STU stu[], int n, int m) +{ + int i, j, k, t; + for (i=0; i=0 && stu[i].score[j]<60)t[0]++; + else if (stu[i].score[j]<70) t[1]++; + else if (stu[i].score[j]<80) t[2]++; + else if (stu[i].score[j]<90) t[3]++; + else if (stu[i].score[j]<100) t[4]++; + else if (stu[i].score[j] == 100) t[5]++; + } + for (i=0; i<=5; i++) + { + if (i==0) printf("<60\t%d\t%.2f%%\n",t[i],(float)t[i]/n*100); + else if (i==5) printf("%d\t%d\t%.2f%%\n", +(i+5)*10,t[i],(float)t[i]/n*100); + else printf("%d-%d\t%d\t%.2f%%\n", +(i+5)*10, (i+5)*10+9, t[i], (float)t[i]/n*100); + } + } +} + +// 15函数功能: 打印学生成绩 +void PrintScore(STU stu[], int n, int m) +{ + int i, j; + for (i=0; i