1、一. 课程设计目的和要求(一). 课程设计目的本课程设计是重要的实践性环节之一,是在学生学习完程序设计语言(C)课程后进行的一次全面的综合练习。本课程设计的目的和任务:1. 巩固和加深学生对 C 语言课程的基本知识的理解和掌握2. 掌握 C 语言编程和程序调试的基本技能3. 利用 C 语言进行基本的软件设计4. 掌握书写程序设计说明文档的能力5. 提高运用 C 语言解决实际问题的能力(二). 课程设计要求1. 分析课程设计题目的要求2. 写出详细设计说明3. 编写程序代码,调试程序使其能正确运行4. 设计完成的软件要便于操作和使用4. 设计完成后提交课程设计报告二. 课程设计任务内容设计一个学
2、生成绩管理系统。系统功能:1)具备对学生基础数据的维护功能(添加、删除、修改)2)具备对课程基础数据的维护功能(添加、删除、修改)3)具备对学生成绩数据的维护功能(添加、删除、修改)4) 具备对成绩的查询功能(按学号、姓名、或课程名查询成绩,排序等 )5) 具备对成绩的统计功能(最高分,最低分,平均分,及格率等)6) 采用菜单界面三. 总体设计说明1 工程设计说明(工程中有哪些文件组成,各有什么作用)该工程文件中有 student.h, studentmain.c, student.c, course.c, scgrade.c query.c tongji.c。 student.h 是头文件,
3、主要存放一些其他函数共用的东西,比如结构体之类的。Studentmain.c 存放 main 函数主菜单程序。其他几个是存放的实现各个功能的函数。另外,还有 STUDENT.DAT,COURSE.DAT,GRADE.DAT 三个文件,主要存放学生,课程,成绩的信息的。还有一个 TEMP.DAT 文件,用于暂时存放数据。2 菜单结构设计(列出各级菜单)3 数据结构设计(三个数据文件用到的的结构定义)学生结构体:struct studentlong sno;char sname20;char sclass20;课程结构体:struct courseint cno;char cname30;成绩结构
4、体:struct scgradelong sno;int cno;float grade;四. 详细设计说明1 学生数据维护子系统设计说明(每个功能模块的设计思路,哪些功能是自己增强的, 加注释的源代码)#include#include“STUDENT.H“/该部分为学生主菜单程序,分别调用添加,修改,删除三个函数。void studentmenu() void addstudent();void modistudent();void deletestudent();char a;while(1) puts(“n“);puts(“ 系 统 主 菜 单“);puts(“ 1: 学 生 数 据 添
5、 加“);puts(“ 2: 学 生 数 据 修 改“);puts(“ 3: 学 生 数 据 删 除“);puts(“ 0: 退 出 系 统“);printf(“请输入数字选择: “);a=getche();switch(a)case 1:addstudent();break;case 2:modistudent();break;case 3:deletestudent();break;case 0:system(“cls“);return;default: return;/添加数据void addstudent() FILE *fp;struct student s;struct stude
6、nt sw;char ch;int flag=0;/打开文件。fp=fopen(“d:STUDENTSTUDENT.dat“,“ab+“); if(!fp) printf(“Create file error!n“); return; dodo /*输入一条学生信息,另外,增加了检验数据是否重复的功能*/printf(“nEnter a student number name class:“);fflush(stdin);scanf(“%ld%s%s“,rewind(fp);while(!feof(fp) fread(if(sw.sno=s.sno) flag=1;printf(“数据输入重复
7、,请重新输入!“);break;while(flag);fwrite(/ 提示是否继续输入。printf(“Input another student? y/n“);ch=getche();while(ch=y);fclose(fp);/修改数据void modistudent() FILE *fp;char ch;struct student s, modis;int found=0;fp=fopen(“D:STUDENTSTUDENT.dat“,“rb+“);if(!fp) printf(“Create file error!n“); return; /*显示文件中的所有学生信息 */fr
8、ead(PRINT1;while(!feof(fp)PRINT2;PRINT1;fread(/*提示输入要修改的学生号 , 存入 modis.sno*/printf(“please enter the no of the modify“);scanf(“%ld“,/*找到要修改的学生并显示 */rewind(fp);while( 1 ) fread(if(feof(fp) break;if(s.sno=modis.sno) found=1; break;if(!found) printf(“未找到你要找的数据!“);return; elsePRINT2;printf(“n 你确实要修改该学生的
9、其他信息吗?(Y/N)“);ch=getche();if(ch=Y|ch=y) /*提示输入要修改的学生姓名 , 存入 modis.sname*/printf(“nplease enter the name of the modifyn“);scanf(“%s“,modis.sname);printf(“nplease enter the class of the modifyn“);scanf(“%s“,modis.sclass);fseek(fp,-(int)sizeof(s),SEEK_CUR); /*从当前位置向前移动一个 s 的长度*/*将 modis 写到文件(覆盖原数据 ) */
10、fwrite(fclose(fp); /删除数据。void deletestudent() FILE *fp,*fp1;char ch;int found=0,num;struct student s;fp=fopen(“D:studentstudent.dat“,“rb“);if(!fp) printf(“Create file error!“);return;/*显示文件中的所有学生信息 */fread(PRINT1;while(!feof(fp) PRINT2;PRINT1;fread(printf(“please enter the no of the delete“);scanf(“
11、%d“, /找到要修改的学生信息,显示!rewind(fp);while(1) fread(if(feof(fp) break;if(s.sno=num) found=1;break;if(!found) printf(“未找到你要找的数据!“);return;elsePRINT2;printf(“n 你确实要删除该学生的信息吗?(Y/N)“);ch=getche();/将删除后的信息复制到 temp 文件中。if(ch=Y|ch=y) fp1=fopen(“D:studenttemp.dat“,“wb“);rewind(fp);while(1) fread(if(feof(fp) break
12、;if(s.sno!=num) fwrite(fclose(fp1);fclose(fp);将 temp 文件的信息再重新覆盖掉原来的 student 文件。fp=fopen(“D:studentstudent.dat“,“wb“);fp1=fopen(“D:studenttemp.dat“,“rb“);while(1) fread(if(feof(fp1) break;fwrite(fclose(fp1);fclose(fp);2 课程数据维护子系统设计说明#include#include“STUDENT.H“void coursemenu() void addcourse();void m
13、odicourse();void deletecourse();char a;while(1) puts(“n“);puts(“ 系 统 主 菜 单“);puts(“ 1: 课 程 数 据 添 加“);puts(“ 2: 课 程 数 据 修 改“);puts(“ 3: 课 程 数 据 删 除“);puts(“ 0: 退 出 系 统“);printf(“请输入数字选择: “);a=getche();switch(a)case 1:addcourse();break;case 2:modicourse();break;case 3:deletecourse();break;case 0:syste
14、m(“cls“);return;default: return;/添加数据。void addcourse() FILE *fp;struct course c,cw; char ch;int flag=0;fp=fopen(“d:STUDENTCOURSE.dat“,“ab+“); if(!fp) printf(“Create file error!n“); return; /输入一条课程信息,提示是否重新输入,另外增加检验数据是否重复的功能。dodoprintf(“nEnter a course number name:“);fflush(stdin);scanf(“%d%s“,rewind
15、(fp);while(!feof(fp) fread(if(o=o) flag=1;printf(“数据输入重复,请重新输入!“);break;while(flag);fwrite(printf(“Input another course? y/n“);ch=getche();while(ch=y);fclose(fp);/修改数据void modicourse() FILE *fp;char ch;struct course c, modis;int found=0;fp=fopen(“D:STUDENTCOURSE.dat“,“rb+“);if(!fp) printf(“Create fi
16、le error!n“); return; /*显示文件中的所有课程信息 */fread(PRINT1;while(!feof(fp)PRINT3;PRINT1;fread(/*提示输入要修改的课程号 , 存入 modis.sno*/printf(“please enter the no of the modify“);scanf(“%d“,/*找到要修改的课程并显示 */rewind(fp);while( 1 ) fread(if(feof(fp) break;if(o=o) found=1; break;if(!found) printf(“未找到你要找的数据!“);return; els
17、ePRINT3;printf(“n 你确实要修改该课程的其他信息吗?(Y/N)“);ch=getche();if(ch=Y|ch=y) /*提示输入要修改的课程名 , 存入 ame*/printf(“nplease enter the name of the modifyn“);scanf(“%s“,ame);fseek(fp,-sizeof(c),SEEK_CUR); /*从当前位置向前移动一个 s 的长度*/*将 modis 写到文件(覆盖原数据 ) */fwrite(fclose(fp); /删除数据。void deletecourse() FILE *fp,*fp1;char ch;i
18、nt found=0,num;struct course c;fp=fopen(“D:studentCOURSE.dat“,“rb“);if(!fp) printf(“Create file error!“);return;/显示文件中的信息。fread(PRINT1;while(!feof(fp) PRINT3;PRINT1;fread(/*提示输入要修改的课程号 , 存入 num*/printf(“please enter the no of the delete“);scanf(“%d“, /*找到要修改的课程并显示 */rewind(fp);while(1) fread(if(feof
19、(fp) break;if(o=num) found=1;break;if(!found) printf(“未找到你要找的数据!“);return;elsePRINT3;printf(“n 你确实要删除该学生的信息吗?(Y/N)“);ch=getche();/将删除后的文件复制到 temp 文件中。if(ch=Y|ch=y) fp1=fopen(“D:studenttemp.dat“,“wb“);rewind(fp);while(1) fread(if(feof(fp) break;if(o!=num) fwrite(fclose(fp1);fclose(fp);/将 temp 文件中的信息覆
20、盖掉原来 course 的文件中。fp=fopen(“D:studentCOURSE.dat“,“wb“);fp1=fopen(“D:studenttemp.dat“,“rb“);while(1) fread(if(feof(fp1) break;fwrite(fclose(fp1);fclose(fp);3 成绩数据维护子系统设计说明#include#include“STUDENT.H“void grademenu() void addgrade();void modigrade();void deletegrade();char a;while(1) puts(“n“);puts(“ 系
21、统 主 菜 单“);puts(“ 1: 成 绩 数 据 添 加“);puts(“ 2: 成 绩 数 据 修 改“);puts(“ 3: 成 绩 数 据 删 除“);puts(“ 0: 退 出 系 统“);printf(“请输入数字选择: “);a=getche();switch(a)case 1:addgrade();break;case 2:modigrade();break;case 3:deletegrade();break;case 0:system(“cls“);return;default: return;/添加成绩!void addgrade() FILE *fp;struct
22、scgrade sc; struct scgrade scw;char ch;int flag=0;fp=fopen(“d:STUDENTGRADE.dat“,“ab+“); if(!fp) printf(“Create file error!n“); return; /输入一条成绩信息,提示是否重新输入,另外增加检验数据是否重复的功能dodo printf(“nEnter a student number ,a course number, grade :“);fflush(stdin);scanf(“%ld%d%f“,if(sc.grade100) flag=1;printf(“n 输入成
23、绩格式不正确,请重新输入“);rewind(fp);while(!feof(fp) fread(if(o=oprintf(“n 数据输入重复,请重新输入!“);break;while(flag);fwrite(printf(“Input another students grade? y/n“);ch=getche();while(ch=y);fclose(fp);/修改数据void modigrade() FILE *fp;char ch;struct scgrade sc, modis;int found=0;fp=fopen(“D:STUDENTGRADE.dat“,“rb+“);if(
24、!fp) printf(“Create file error!n“); return; /*显示文件中的所有成绩信息 */fread(PRINT1;while(!feof(fp)PRINT4;PRINT1;fread(/*提示输入要修改的学生号 , 存入 modis.sno*/printf(“please enter the no of the modify“);scanf(“%ld“,/*找到要修改的学生成绩并显示 */rewind(fp);while( 1 ) fread(if(feof(fp) break;if(sc.sno=modis.sno) found=1; break;if(!f
25、ound) printf(“未找到你要找的数据!“);return; elsePRINT4;printf(“n 你确实要修改该学生的其他信息吗?(Y/N)“);ch=getche();if(ch=Y|ch=y) /*提示输入要修改的学生课程名和成绩 , 存入 o 和 modis.grade*/printf(“nplease enter the course number of the modifyn“);scanf(“%d“,printf(“nplease enter the grade of the modifyn“);scanf(“%f“,fseek(fp,-(int)sizeof(sc)
26、,SEEK_CUR); /*从当前位置向前移动一个 sc 的长度*/*将 modis 写到文件(覆盖原数据 ) */fwrite(fclose(fp); /删除数据void deletegrade() FILE *fp,*fp1;char ch;int found=0,num;struct scgrade sc;fp=fopen(“D:studentGRADE.dat“,“rb“);if(!fp) printf(“Create file error!“);return;/显示文件中的信息fread(PRINT1;while(!feof(fp) PRINT4;PRINT1;fread(/*提示输
27、入要删除的学号, 存入 num*/printf(“please enter the no of the delete“);scanf(“%d“, /*找到要删除的成绩并显示 */rewind(fp);while(1) fread(if(feof(fp) break;if(sc.sno=num) found=1;break;if(!found) printf(“未找到你要找的数据!“);return;elsePRINT4;printf(“n 你确实要删除该学生的信息吗?(Y/N)“);ch=getche();/将删除后的文件复制到 temp 文件中。if(ch=Y|ch=y) fp1=fopen
28、(“D:studenttemp.dat“,“wb“);rewind(fp);while(1) fread(if(feof(fp) break;if(sc.sno!=num) fwrite(fclose(fp1);fclose(fp);/将 temp 文件中的信息覆盖掉原来 course 的文件中。fp=fopen(“D:studentGRADE.dat“,“wb“);fp1=fopen(“D:studenttemp.dat“,“rb“);while(1) fread(if(feof(fp1) break;fwrite(fclose(fp1);fclose(fp);4 查询数据维护子系统设计说明
29、#include#include#include“STUDENT.H“void query() void snoquery();void snamequery();void cnamequery();void cnamequeryson();void classandcnamequery();char a;while(1) puts(“n“);puts(“ 系 统 主 菜 单“);puts(“ 1: 按 学 号 查 询 成 绩“);puts(“ 2: 按 姓 名 查 询 成 绩“);puts(“ 3: 按 课 名 查 询 成 绩“);puts(“ 4: 按 课 名 查 询 成 绩(子函数)“)
30、;puts(“ 5: 按 班 名 课 名 查 询 成 绩“);puts(“ 0: 退 出 系 统“);printf(“请输入数字选择: “);a=getche();switch(a)case 1:snoquery();break;case 2:snamequery();break;case 3:cnamequery();break;case 4:cnamequeryson();break;case 5:classandcnamequery();break;case 0:system(“cls“);return;default: return;/按学号查询void snoquery() FILE
31、 *fp;struct scgrade sc; char ch;long no;int found=0;fp=fopen(“d:STUDENTGRADE.dat“,“rb“);if(!fp) printf(“Create file error!n“); return; /提示要查询成绩的学号。printf(“nEnter a student number of the query:“);scanf(“%ld“,/显示并输出。while(1) fread(if(feof(fp) break;if(sc.sno=no) found=1; PRINT1;PRINT4;PRINT1;if(!found
32、) printf(“未找到你要找的数据!“);return; fclose(fp);/按姓名查询void snamequery() FILE *fp;struct student s;struct scgrade sc; char ch,name20;long no;int found=0;fp=fopen(“d:STUDENTSTUDENT.dat“,“rb“);if(!fp) printf(“Create file error!n“); return; /提示输入要查询成绩的姓名。printf(“nEnter a student name of the query:“);scanf(“%s
33、“,name);/找到该生的的学号。while(1) fread(if(feof(fp) break;if(strcmp(s.sname,name)=0) found=1;no=s.sno;/PRINT1;/PRINT2;/PRINT1;if(!found) printf(“未找到你要找的数据!“);return; fclose(fp);fp=fopen(“d:STUDENTGRADE.dat“,“rb“);found=0;if(!fp) printf(“Create file error!n“); return; /找到该生成绩,并显示。while(1) fread(if(feof(fp)
34、break;if(sc.sno=no) found=1; PRINT1;PRINT4;PRINT1;if(!found) printf(“未找到你要找的数据!“);return; fclose(fp);/按课名查询void cnamequery() FILE *fp;struct course c;struct scgrade sc,temp;struct scgrade grades80;char name20;int no,i,j,n=0;int found=0;fp=fopen(“d:STUDENTCOURSE.dat“,“rb“);if(!fp) printf(“Create file
35、 error!n“); return; /提示输入要查询的课程名printf(“nEnter a course name of the query:“);scanf(“%s“,name);/找到该课程的课称号。while(1) fread(if(feof(fp) break;if(strcmp(ame,name)=0) found=1;no=o;/PRINT1;/PRINT3;/PRINT1;if(!found) printf(“未找到你要找的数据!“);return; fclose(fp);fp=fopen(“d:STUDENTGRADE.dat“,“rb“);found=0;if(!fp)
36、 printf(“Create file error!n“); return; /在成绩信息中找到该课程号的成绩while(1) fread(if(feof(fp) break;if(o=no) found=1;gradesn=sc;n=n+1;/PRINT1;/PRINT4;/排序for(i=0;i#include#include“STUDENT.H“void tongji() void cnametongji();void classtongji();void classandcnametongji();void classandcnametongjifour();void classes
37、average();char a;while(1) puts(“n“);puts(“ 系 统 主 菜 单“);puts(“ 1: 按 课 名 统 计 成 绩“);puts(“ 2: 按 班 名 统 计 成 绩“);puts(“ 3: 按 课 名 班 名 统 计 成 绩“);puts(“ 4: 按 课 名 班 名 优 良 中 差 人 数“);puts(“ 5: 统 计 各 班 平 均 成 绩“);puts(“ 0: 退 出 系 统“);printf(“请输入数字选择: “);a=getche();switch(a)case 1:cnametongji();break;case 2:classto
38、ngji();break;case 3:classandcnametongji();break;case 4:classandcnametongjifour();break;case 5:classesaverage();break;case 0:system(“cls“);return;default: return;/按课名统计void cnametongji() FILE *fp;struct course c;struct scgrade sc;struct scgrade grades80;char name20;int no,i,p=0,n=0;int found=0;float
39、max=0,min=0,sum=0,average,peng;fp=fopen(“d:STUDENTCOURSE.dat“,“rb“);if(!fp) printf(“Create file error!n“); return; /提示输入要统计的课程名。printf(“nEnter a course name of the tongji:“);scanf(“%s“,name);/找到该课程的课程号。while(1) fread(if(feof(fp) break;if(strcmp(ame,name)=0) found=1;no=o;/PRINT1;/PRINT3;/PRINT1;if(!found) printf(“未找到你要找的数据!“);return; fclose(fp);fp=fopen(“d:STUDENTGRADE.dat“,“rb“);found=0;if(!fp) printf(“Create file error!n“); return; /找到该课程的相关成绩。while(1) fread(if(feof(fp) break;if(o=no) found=1;gradesn=sc;n=n+1;/PRINT1;/PRINT4;