diff --git a/hello.md b/hello.md deleted file mode 100644 index 11184d9..0000000 --- a/hello.md +++ /dev/null @@ -1,13 +0,0 @@ -```` -//输入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); - } -} - diff --git a/lyx16.md b/lyx16.md deleted file mode 100644 index 3a28f73..0000000 --- a/lyx16.md +++ /dev/null @@ -1,27 +0,0 @@ - -void StatisticAnalysis(STU stu[], int n, int m) -{ - int i, j, t[6]; - for (j=0; j=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); - } - } -} \ No newline at end of file diff --git a/lyx6.md b/lyx6.md deleted file mode 100644 index 87e453a..0000000 --- a/lyx6.md +++ /dev/null @@ -1,4 +0,0 @@ -int Descending(float a, float b) -{ - return a > b; - } \ No newline at end of file diff --git a/readme1.md b/readme1.md index e8a4685..09c0afb 100644 --- a/readme1.md +++ b/readme1.md @@ -13,383 +13,758 @@ | 任务 | 设计 | 开发 | 测试 | 文档 | | ---- | ---- | ---- | ---- | ---- | -| 输入n个学生的m门课成绩 |张桐桐| 张桐桐 | 李玉璇 | 张桐桐 | -| 输入n个学生的m门课成绩| 成员2 | 成员2 | 成员3 | 成员2 | -| 按选择法将数组num的元素值按从低到高排序 | ... | ... | ... | ... | -| 按学号查找学生成绩并显示查找结果| ... | ... | ... | ... | -| | ... | ... | ... | ... | -|| ... | ... | ... | ... | -| | ... | ... | ... | ... | - - - -项目开发过程中采用 Kanban(看板)进行任务管理和分工协作,并使用 Git 对程序代码和文档进行版本管理。任务分工情况如下: - -| 任务 | 设计 | 开发 | 测试 | 文档 | -| ---- | ---- | ---- | ---- | ---- | -| C1-C3 菜单驱动的用户界面 | 成员1 | 成员1 | 成员2,成员3 | 成员1 | -| C4 添加库存记录 | 成员2 | 成员2 | 成员3 | 成员2 | -| ... | ... | ... | ... | ... | -| ... | ... | ... | ... | ... | +| 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 | 每个成员的工作量(百分比): -| 成员1 | 成员2 | 成员3 | -| ---- | ---- | ---- | -| 40 | 30 | 30 | +| 张桐桐 | 李玉璇 | 周羽凡 |孟婷玉| +| ---- | ---- | ---- |----| +| | | | | -## 关于零件库存管理系统 -设计一个库存零件管理系统,要求采用命令行菜单界面进行交互,具备读取、保存、打印、查询、修改、插入、删除和排序等基本功能,能够以表格和图表形式展示数据,采用 CSV 格式保存数据。 +关于学生成绩管理系统 +设计一个学生成绩管理系统,要求采用行菜单界面进行交互,具备读取、保存、打印、查询、插入和排序等基本功能,能够以表格和图表形式展示数据,采用CSV格式保存数据。 系统的功能性需求: -- 数据的读取、保存、打印、查询、修改、插入、删除、排序和图表展示。 +数据的读取、保存、打印、查询、插入、排序和图表展示。 系统的非功能性需求: -- 菜单驱动的命令行交互界面。 - - -## 需求分析 +菜单驱动的命令行交互界面 +需求分析 分析系统的功能需求和界面需求,编制用户手册如下。 -#### C1: 启动程序 - -命令行中执行命令 `./app`,系统启动,显示提示信息,然后显示功能菜单,等待用户输入命令。 -``` -库存管理系统启动 - -1 读取 | 2 保存 | 3 打印 | 4 查询 | 5 添加 -6 修改 | 7 删除 | 8 排序 | 9 图表 | 0 退出 - -请选择: -``` - - - -#### C2: 显示命令菜单 - -``` -1 读取 | 2 保存 | 3 打印 | 4 查询 | 5 添加 -6 修改 | 7 删除 | 8 排序 | 9 图表 | 0 退出 - -请选择: -``` - - - -#### C3: 计算每门课程的总分和平均分 - -选择菜单命令 `3`, - -``` -请选择:0 -确定要退出吗?(Y/N): y -程序退出 - -``` -![总分和平均值](ztt1.drawio.svg) - - - -#### C4: 添加库存记录 - -选择菜单命令 `5`,提示输入零件编号,若该零件不存在,则继续输入零件名称、库存数量,添加零件,并提示完成;若零件编号已存在,则提示零件已存在,并结束。 - -``` -请选择:5 -输入零件编号:101 -输入零件名:电脑 -输入库存数:20 -零件 101 已添加 - -1 读取 | 2 保存 | 3 打印 | 4 查询 | 5 添加 -6 修改 | 7 删除 | 8 排序 | 9 图表 | 0 退出 - -请选择:5 -输入零件编号:101 -零件已存在. -``` - - -#### C5: 数据按升序排序 - -选择菜单命令 `4`, - -``` -请选择:4 -输入零件编号:101 -零件编号:101 -零件名称:电脑 -零件库存:20 - -1 读取 | 2 保存 | 3 打印 | 4 查询 | 5 添加 -6 修改 | 7 删除 | 8 排序 | 9 图表 | 0 退出 - -请选择:4 -输入零件编号:100 -零件不存在. - -``` - - - -#### C6: 打印库存列表 - -选择菜单命令 `3`,打印 - -``` -请选择:3 -------------------------------------------------------- -| NUMBER | NAME | ON HAND | -------------------------------------------------------- -| 101 | 电脑 | 20 | -------------------------------------------------------- - -``` - - - -#### C7: 修改库存记录 - -选择菜单命令 `6`,根据提示输入零件编号,若零件存在,则继续输入新的零件名和库存数量,并修改库存记录;否则,提示零件不存在并结束。 - -``` -请选择:6 -输入零件编号:101 -输入零件名:笔记本电脑 -输入库存数:12 -零件 101 已更新 - -1 读取 | 2 保存 | 3 打印 | 4 查询 | 5 添加 -6 修改 | 7 删除 | 8 排序 | 9 图表 | 0 退出 - -请选择:3 -------------------------------------------------------- -| NUMBER | NAME | ON HAND | -------------------------------------------------------- -| 101 | 笔记本电脑 | 12 | -------------------------------------------------------- - -1 读取 | 2 保存 | 3 打印 | 4 查询 | 5 添加 -6 修改 | 7 删除 | 8 排序 | 9 图表 | 0 退出 - -请选择:6 -输入零件编号:100 -零件不存在. - -``` - - - -#### C8: 删除库存记录 - -选择菜单命令 `7`,根据提示输入零件编号,若零件存在,则删除之;否则提示零件不存在并结束。 - -``` -请选择:7 -输入零件编号:100 -零件不存在. - -1 读取 | 2 保存 | 3 打印 | 4 查询 | 5 添加 -6 修改 | 7 删除 | 8 排序 | 9 图表 | 0 退出 - -请选择:7 -输入零件编号:101 -零件 101 已删除 - -1 读取 | 2 保存 | 3 打印 | 4 查询 | 5 添加 -6 修改 | 7 删除 | 8 排序 | 9 图表 | 0 退出 - -请选择:3 -------------------------------------------------------- -| NUMBER | NAME | ON HAND | -------------------------------------------------------- -------------------------------------------------------- - -``` - - - -#### C9: 库存记录排序 - -选择菜单命令 `8`,对库存记录按零件编号从小到大排序。 - -``` -请选择:3 -------------------------------------------------------- -| NUMBER | NAME | ON HAND | -------------------------------------------------------- -| 101 | 电脑 | 20 | -| 100 | 打印机 | 10 | -------------------------------------------------------- - -1 读取 | 2 保存 | 3 打印 | 4 查询 | 5 添加 -6 修改 | 7 删除 | 8 排序 | 9 图表 | 0 退出 - -请选择:8 -排序 -排序已完成 - -1 读取 | 2 保存 | 3 打印 | 4 查询 | 5 添加 -6 修改 | 7 删除 | 8 排序 | 9 图表 | 0 退出 - -请选择:3 -------------------------------------------------------- -| NUMBER | NAME | ON HAND | -------------------------------------------------------- -| 100 | 打印机 | 10 | -| 101 | 电脑 | 20 | -------------------------------------------------------- - -``` - - - -#### C10: 从文件中读取库存记录 - -选择菜单命令 `1`,提示输入文件名,若文件存在,则打开文件读取 CSV 格式保存的所有库存记录;否则,若文件不存在,则给出错误信息并结束。 - -假设文件 `a.csv` 中,以 CSV (Comma-Separated Values)格式保存了如下记录: - -``` -103,显示器,8 -104,手机,12 -101,电脑,20 -102,打印机,10 -``` - -则读取记录的过程如下: - -``` -请选择:1 -读取数据 -请输入文件名:a.csv -读取 4 记录 - -1 读取 | 2 保存 | 3 打印 | 4 查询 | 5 添加 -6 修改 | 7 删除 | 8 排序 | 9 图表 | 0 退出 - -请选择:3 -------------------------------------------------------- -| NUMBER | NAME | ON HAND | -------------------------------------------------------- -| 103 | 显示器 | 8 | -| 104 | 手机 | 12 | -| 101 | 电脑 | 20 | -| 102 | 打印机 | 10 | -------------------------------------------------------- - -1 读取 | 2 保存 | 3 打印 | 4 查询 | 5 添加 -6 修改 | 7 删除 | 8 排序 | 9 图表 | 0 退出 - -请选择:1 -读取数据 -请输入文件名:a -a: No such file or directory - -``` - - - -#### C11: 将库存保存保存到文件 - -选择菜单命令 `2`,提示输入文件名,将所有库存记录以 CSV 格式保存到指定的文件中。 - -``` -请选择:2 -保存数据 -请输入文件名:b.csv -保存 4 记录 - -``` - - - -#### C12: 以图表方式显示库存记录 - -选择菜单命令 `9`,以图表方式显示库存记录。 - -``` -请选择:9 -图表 - 103 : 显示器 | ******** (8) - 104 : 手机 | ************ (12) - 101 : 电脑 | ******************** (20) - 102 : 打印机 | ********** (10) - -1 读取 | 2 保存 | 3 打印 | 4 查询 | 5 添加 -6 修改 | 7 删除 | 8 排序 | 9 图表 | 0 退出 - -``` - - -## 概要设计 - +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 确认,则退出程序。 +```` +Please Input your choice: 0 +Are you sure you want to exit?(Y/N): y +End of program! +```` +C4: 添加学生信息 +选择菜单命令 1 ,假设n=4,m=3,提示输入学生的学号,姓名和成绩,然后利用循环逐个输入学生的学号和姓名以及各科成绩。 +```` +Please Input your choice: 1 +Input student's ID, name and score: +2214111006 XuZilin 100 95 86 +2214111009 XuZigui 77 89 99 +2214111011 ZhangYu 85 91 98 +2214111025 LiYujia 75 89 100 +```` +C5: 计算学生各门课程总分和平均分 +选择菜单命令 2 ,计算学生各门课程总分和平均分,然后利用循环逐个输出学生的顺序,总成绩和平均分,结果都取整数。 +```` +Please Input your choice: 2 +student 1: sum = 281, aver = 93 +student 2: sum = 265, aver = 88 +student 3: sum = 274, aver = 91 +student 4: sum = 264, aver = 88 +```` +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)。 +数据处理模块包括读取数据(read_data)、保存数据(save_data)、打印数据(print_data)、查询数据(query_data)、添加数据(add_data)、更新数据(update_data)、删除数据(delete_data)、数据排序(sort_data)和生成图表(make_chart)等子模块。其中查询、添加、更 +新和删除数据还会用到根据编号查询数据的方法(find)。 上述各模块通过主程序(main)进行调用,系统模块图如下。 - -![系统模块图](images/module.drawio.svg) +![添加库存记录流程图](test.drawio.svg) 各模块的主要功能如下: -#### main - +main 系统主函数模块,显示菜单,根据用户选择的菜单命令,执行相关操作。 -#### init - -系统初始化。 - -#### display_menu +init +系统初始化 -显示菜单命令。 - - -## 详细设计 +menu +显示菜单命令 +详细设计 针对概要设计 -#### main - -Step 1: 初始化 -Step 2: 根据用户选择的命令执行对应的操作 -Step 2.1: 显示菜单 -Step 2.2: 选择菜单命令 c -Step 2.3: if c == CMD_READ then 读取数据 -Step 2.4: if c == CMD_SAVE then 保存数据 -Step 2.5: if c == CMD_PRINT then 打印数据 -Step 2.6: - - -![主程序流程图](images/main.drawio.svg) - - -#### save_data - -Step 1: 输入文件名 -Step 2: 打开文件 -Step 3: if 打开文件失败 then 提示打开文件失败并结束 -Step 4: 将所有库存记录写入文件 -Step 5: 关闭文件 - - -![保存数据流程图](images/save_data.drawio.svg) - -#### add_data - -Step 1: if 数据库满 then 提示数据库满并结束 -Step 2: 输入零件编号 -Step 3: if 零件已存在 then 提示零件已存在并结束 -Step 4: 输入零件名和库存数量 -Step 5: 添加新零件到数据 -Step 6: 提示添加成功 - -![添加库存记录流程图](test.drawio.svg) -![总分和平均值](ztt1.drawio.svg) - +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 +代码实现 +// 头文件的使用 + +#include +#include +#include +// define定义的全局变量 + +#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)); //选择法将数组 sum 的元素排序的函数 +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); //选择法将数组 num 的元素值从低到高排序的函数 +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); + scnaf("%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 number:\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("Are you sure you want to exit?(Y/N):"); + 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; +} +// 函数功能:输入 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); + } +} +//函数功能:计算每门课程的总分和平均分 + +void AverSumofEveryCourse(STU stu[],int n,int m) +{ + int i,j; + float sum[COURSE_NUM],aver[COURSE_NUM]; + for(j=0;j b; // 这样比较决定了按降序排序,如果 a>b,则交换 +} +//交换两个单精度浮点型数据 + +void SwapFloat(float *x,float *y) +{ + float temp; + temp = *x; + *x = *y; + *y = temp; +} +//交换两个长整型数据 + +void SwapLong(long *x,long *y) +{ + long temp; + temp = *x; + *x = *y; + *y = temp; +} +//交换两个字符串 + +void SwapChar(char x[],chary[]) +{ + char temp[MAX_LEN]; + strcpy(temp, x); + strcpy(x, y); + strcpy(y, temp); +} +//函数功能:按选择法将数组 num 的元素从低到高排序 + +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); + } + } +} +//函数功能:打印学生成绩 + +void PrintScore(STU stu[],int n,int m) +{ + int i,j; + for (i=0; i