C语言课程设计课程成绩管理系统.doc
目 录1 系统分析11.1 课程设计内容11.2 系统功能需求分析11.3 数据结构设计22 系统设计22.1 总体设计22.2 详细设计32.2.1 界面设计32.2.2 各功能模块的设计53 系统编码设计63.1 main函数63.2 newf()函数83.3 inputf()函数93.4 outputf()函数93.5 search()函数103.6 sort()函数123.7 add()函数163.8 revise()函数173.9 deletef()函数183.10 calculated()函数203.11 bsnhk函数204 系统运行215 总结291 系统分析1.1 课程设计内容设计一课程成绩管理系统,功能包括:1. 输入数据:可输入学生姓名、学号、平时作业成绩、期中考试成绩、期 末考试成绩等数据。2. 编辑数据:可添加、删除、修改数据。3. 计算:计算出平时成绩的平均值;按平时20%,期中20%,期末60%比例计算总评成绩;计算课程的平均成绩。4. 查询:可按姓名、学号查询(精确、模糊)。5. 排序:可按姓名、学号、总评成绩排序。6. 浏览:可浏览输入、查询或排序后的数据。7. 文件操作:可打开、保存、关闭数据文件。1.2 系统功能需求分析本系统应具有以下功能:1、文件操作功能建立学生信息文件,可打开、保存、关闭数据文件,先输入数据,然后保存文件,以后如果要用到的话就直接打开该文件,文件打开的条件是该文件必须存在。2、数据输入功能可输入学生学号、姓名、三次平时成绩和期中期末成绩。每完成一个学生成绩的输入操作,系统会提示是否继续输入,当选Y时则继续输入第二个学生的成绩,当选N时则退回主界面,执行其他功能。3、数据添加、修改、删除功能可添加、修改、删除学生信息。4、计算功能 计算平时成绩的平均值、总评成绩(按平时20%,期中20%,期末60%的比例)和课程平均成绩。5、查询功能 可按学号、姓名查询(精确、模糊)学生信息。6、排序功能 可按学号、姓名和总评成绩排序。7、数据显示功能 可浏览输入、查询和排序后的学生有关成绩信息。1.3 数据结构设计结构体类型struct studentlong num;char name20;float Normal_score1;float Normal_score2;float Normal_score3;float Period_score;float End_score;float ave1;float ave2;float ave3;stu100;其中包含了学号,姓名,三次平均成绩,期中成绩,期末成绩和三个平均成绩。定义学号num为长整形,定义姓名name为字符型数组长度定为20,定义平时成绩Normal_score1-3、期中成绩Period_scor、期末成绩End_score和三个平均成绩ave1-3为浮点型。最后再定义结构体数组包含100个元素。2 系统设计2.1 总体设计按系统分析的功能要求将系统划分为以下几个主要功能模块:1数据文件的建立、打开、保存模块,该模块通过各自的函数(newf()、savef()分别实现文件的建立、打开、保存功能;2数据的输入输出模块,该模块用函数inputf()和outputf()实现学生成绩信息的数据输入,显示学生成绩信息;3数据的查询功能search(),可选择是按学号查询search_num ( )还是对姓名查询search_name ( );4数据的排序功能sort(),可选择是按学号sort_num ( )、姓名sort_name ( )还是总评成绩sort_score()进行排序。5数据的添加add()、修改revise()、删除deletef()模块,该模块通过各自的函数分别实现对学生信息的添加、修改、删除;6.数据的计算calculated()功能,可计算平时的平均成绩、总评成绩和课程平均成绩。2.2 详细设计2.2.1 界面设计欢迎界面设计* Welcome to use the Course Management System by 3108006406 Zhang Zhongquan*1、菜单设计(1)初始菜单界面的设计 *Please Select:1new.file2input the message3output the message4search5sort6add7revise8delete9calculated10exit *(2)二级菜单界面设计a.查询功能界面设计* Search 1. by number 2 .by name*b.排序功能界面设计*Sort 1by number 2by name3by score*2、输入界面的设计Please input the information of the student:NO.:001Name:ZZQNormal_score1:88Normal_score2:99Normal_score3:90Period_score:78End_score:67continue:YorN3、信息显示界面的设计num name Nor_sc1 Nor_sc2 Nor_sc3 Per_sc End_sc ave1 ave2 ave31 ZZQ 88.00 99.00 90.00 78.00 67.00 92.33 74.27 84.402.2.2 各功能模块的设计根据划分的功能模块,定义以下函数实现各功能:1主函数main()2新建、打开保存功能模块的设计新建:newf()函数保存:savef ( ) 函数3数据输入输出模块设计输入:inputf ( ) 函数,此函数用来输入学生信息,并把输入的数据保存在新建的那个文件中。输出:outputf( ) 函数4数据的查询功能设计,可选择是按学号查询还是对姓名查询;学号查询:search_num ( ) 函数姓名查询:search_name ( ) 函数 5数据的排序功能设计,可选择是按学号、姓名还是总评成绩进行排序。学号排序:sort_num ( ) 函数姓名排序:sort_name ( ) 函数总评排序:sort_score()函数6数据的添加、修改、删除模块设计添加:add ( ) 函数,此函数向原有的数据插入一个新的学生信息,并把插入的数据存入原有文件。修改:revise ( ) 函数删除:deletef ( ) 函数7数据的计算功能设计 计算:calculated()函数,此函数用于计算平时成绩的平均值、总评成绩和课程平均成绩。3 系统编码设计# include<stdio.h># include<conio.h># include<dos.h># include<string.h>struct student long num; char name20; float Normal_score1; float Normal_score2; float Normal_score3; float Period_score; float End_score; float ave1; float ave2; float ave3; stu100;char a20; /*文件名变量,新建的文件名存储在字符数组a*/ int n=0; /*用来存放学生的个数*/3.1 main函数void main() /*主函数*/void newf();void savef();void inputf();void outputf();void search();void sort();void add();void revise();void deletef();void calculated();int i;clrscr(); /*清屏*/*以下是系统的欢迎界面*/gotoxy(15,8);for(i=0;i<50;i+)printf("*");gotoxy(18,11);printf("Welcome to use the Course Management System");gotoxy(27,13);printf("by 3108006406 Zhang Zhongquan");gotoxy(15,16);for(i=0;i<50;i+)printf("*");sleep(3); loop : /*以下循环体是系统初始菜单,用户可根据不用需求选用不同功能*/ clrscr(); gotoxy(15,5); for(i=0;i<50;i+) printf("*"); gotoxy(30,6); printf("Please Select"); gotoxy(30,7); printf("1. new.file"); gotoxy(30,8); printf("2. input the message"); gotoxy(30,9); printf("3. output the message"); gotoxy(30,10); printf("4. search"); gotoxy(30,11); printf("5. sort"); gotoxy(30,12); printf("6. add"); gotoxy(30,13); printf("7. revise"); gotoxy(30,14); printf("8. delete"); gotoxy(30,15); printf("9. calculated"); gotoxy(30,16); printf("10.exit"); gotoxy(15,17); for(i=0;i<50;i+) printf("*"); printf("n"); printf("please select the menu:"); scanf("%d",&i); if(i<1|i>10)printf("error"); else switch(i) case 1:newf();break; case 2:inputf();break; case 3:outputf();break; case 4:search();break; case 5:sort();break; case 6:add();break; case 7:revise();break; case 8:deletef();break; case 9:calculated();break; case 10:exit(0);break; goto loop;3.2 newf()函数void newf() /*此函数用来新建文件*/FILE *fp;printf("please input the name of the file:");scanf("%s",a); if(fp=fopen(a,"w+")=NULL) printf("cannot open the filen"); exit(0); fclose(fp);void savef() /*此函数将数据写入文件,保存数据*/FILE *fp;int i; if(fp=fopen(a,"w")=NULL) printf("cannot open filen"); return; for(i=0;i<n;i+)if(fwrite(&stui,sizeof(struct student),1,fp)!=1)printf("file write errorn");fclose(fp);3.3 inputf()函数void inputf() /*此函数用于输入学生有关成绩等信息*/int i;char t;printf("please input the information of the student:n"); for(i=0;i<100;i+) printf("No.:");scanf("%ld",&stui.num); printf("name:");scanf("%s",&stui.name); printf("Normal_score1:");scanf("%f",&stui.Normal_score1); printf("Normal_score2:");scanf("%f",&stui.Normal_score2); printf("Normal_score3:");scanf("%f",&stui.Normal_score3); printf("Period_score:");scanf("%f",&stui.Period_score); printf("End_score:");scanf("%f",&stui.End_score); n=n+1; printf("continue:'Y'or'N'n"); t=getchar(); t=getchar(); if(t='N') break; ;savef();3.4 outputf()函数void outputf() /*此函数将学生信息在屏幕上输出*/ int i;FILE *fp; if(fp=fopen(a,"r")=NULL) printf("cannot open filen"); return; printf("nnumtnametNor_sc1tNor_sc2tNor_sc3tPer_sctEnd_sctave1tave2tave3tn"); for(i=0;i<n;i+) fread(&stui,sizeof(struct student),1,fp); printf("%-5ldt%-7st%-5.2ft%-5.2ft%-5.2ft%-5.2ft%-5.2ft%-5.2ft%-5.2ft%-5.2ftn",stui.num,stui.name,stui.Normal_score1,stui.Normal_score2,stui.Normal_score3,stui.Period_score,stui.End_score,stui.ave1,stui.ave2,stui.ave3); fclose(fp);sleep(3);printf("npress enter back to the menu:n");getch();3.5 search()函数void search() /*此函数用于查询学生有关信息*/void search_num(); /*此函数用于按学号查询学生有关信息*/void search_name(); /*此函数用于按姓名查询学生有关信息*/int b;printf(" *nn");printf(" searchn");printf(" 1.by numbern");printf(" 2.by namen");printf("n *n");printf("please select the menu:n");scanf("%d",&b);if(b=1)search_num();else search_name();void search_num() /*此函数用于按学号查询学生有关信息*/int sch_num;int i;printf("nplease enter the num which do you want to search:");scanf("%d",&sch_num);for(i=0;i<n;i+) if(sch_num=stui.num) printf("nnumtnametNor_sc1tNor_sc2tNor_sc3tPer_sctEnd_sctave1tave2tave3tn"); printf("%-5ldt%-7st%-5.2ft%-5.2ft%-5.2ft%-5.2ft%-5.2ft%-5.2ft%-5.2ft%-5.2ftn",stui.num,stui.name,stui.Normal_score1,stui.Normal_score2,stui.Normal_score3,stui.Period_score,stui.End_score,stui.ave1,stui.ave2,stui.ave3); sleep(2);printf("npress enter back to the menu:");getch();void search_name() /*此函数用于按姓名查询学生有关信息*/int i;char sch_name20;printf("nplease enter the name which do you want to search:");scanf("%s",sch_name);for(i=0;i<n;i+) if(strcmp(sch_name,stui.name)=0) printf("nnumtnametNor_sc1tNor_sc2tNor_sc3tPer_sctEnd_sctave1tave2tave3tn"); printf("%-5ldt%-7st%-5.2ft%-5.2ft%-5.2ft%-5.2ft%-5.2ft%-5.2ft%-5.2ft%-5.2ftn",stui.num,stui.name,stui.Normal_score1,stui.Normal_score2,stui.Normal_score3,stui.Period_score,stui.End_score,stui.ave1,stui.ave2,stui.ave3); sleep(2);printf("npress enter back to the menu:n");getch();3.6 sort()函数void sort() /*此函数用于对输入的数据进行排序*/void sort_num(); /*按学号排序*/void sort_name(); /*按姓名排序*/void sort_score(); /*按总评成绩排序*/int b;printf(" *nn");printf(" sortn");printf(" 1.by numbern");printf(" 2.by namen");printf(" 3.by scoren");printf("n *n");printf("please select the menu:n");scanf("%d",&b); switch(b) case 1:sort_num();break; case 2:sort_name();break; case 3:sort_score();break; void sort_num() /*按学号排序*/FILE *fp;int i,j;struct student a;for(j=0;j<n-1;j+)for(i=0;i<n-j-1;i+) if(stui.num>stui+1.num) a.num=stui.num; strcpy(a.name,stui.name); a.Normal_score1=stui.Normal_score1; a.Normal_score2=stui.Normal_score2; a.Normal_score3=stui.Normal_score3; a.Period_score=stui.Period_score; a.End_score=stui.End_score; a.ave1=stui.ave1; a.ave2=stui.ave2; a.ave3=stui.ave3; stui.num=stui+1.num; strcpy(stui.name,stui+1.name); stui.Normal_score1=stui+1.Normal_score1; stui.Normal_score2=stui+1.Normal_score2; stui.Normal_score3=stui+1.Normal_score3; stui.Period_score=stui+1.Period_score; stui.End_score=stui+1.End_score; stui.ave1=stui+1.ave1; stui.ave2=stui+1.ave2; stui.ave3=stui+1.ave3; stui+1.num=a.num; strcpy(stui+1.name,a.name); stui+1.Normal_score1=a.Normal_score1; stui+1.Normal_score2=a.Normal_score2; stui+1.Normal_score3=a.Normal_score3; stui+1.Period_score=a.Period_score; stui+1.End_score=a.End_score; stui+1.ave1=a.ave1; stui+1.ave2=a.ave2; stui+1.ave3=a.ave3; printf("nnumtnametNor_sc1tNor_sc2tNor_sc3tPer_sctEnd_sctave1tave2tave3tn");fp=fopen("stu_st1","w"); for(i=0;i<n;i+) fwrite(&stui,sizeof(struct student),1,fp); printf("%-5ldt%-7st%-5.2ft%-5.2ft%-5.2ft%-5.2ft%-5.2ft%-5.2ft%-5.2ft%-5.2ftn",stui.num,stui.name,stui.Normal_score1,stui.Normal_score2,stui.Normal_score3,stui.Period_score,stui.End_score,stui.ave1,stui.ave2,stui.ave3); printf("n");fclose(fp);printf("press enter back to the menu:n");getch();void sort_name() /*按姓名排序*/FILE *fp;int i,j;struct student a;for(j=0;j<n-1;j+)for(i=0;i<n-j-1;i+) if(strcmp(stui.name,stui+1.name)>0) a.num=stui.num; strcpy(a.name,stui.name); a.Normal_score1=stui.Normal_score1; a.Normal_score2=stui.Normal_score2; a.Normal_score3=stui.Normal_score3; a.Period_score=stui.Period_score; a.End_score=stui.End_score; a.ave1=stui.ave1; a.ave2=stui.ave2; a.ave3=stui.ave3; stui.num=stui+1.num; strcpy(stui.name,stui+1.name); stui.Normal_score1=stui+1.Normal_score1; stui.Normal_score2=stui+1.Normal_score2; stui.Normal_score3=stui+1.Normal_score3; stui.Period_score=stui+1.Period_score; stui.End_score=stui+1.End_score; stui.ave1=stui+1.ave1; stui.ave2=stui+1.ave2; stui.ave3=stui+1.ave3; stui+1.num=a.num; strcpy(stui+1.name,a.name); stui+1.Normal_score1=a.Normal_score1; stui+1.Normal_score2=a.Normal_score2; stui+1.Normal_score3=a.Normal_score3; stui+1.Period_score=a.Period_score; stui+1.End_score=a.End_score; stui+1.ave1=a.ave1; stui+1.ave2=a.ave2; stui+1.ave3=a.ave3; printf("nnumtnametNor_sc1tNor_sc2tNor_sc3tPer_sctEnd_sctave1tave2tave3tn");fp=fopen("stu_st1","w"); for(i=0;i<n;i+) fwrite(&stui,sizeof(struct student),1,fp); printf("%-5ldt%-7st%-5.2ft%-5.2ft%-5.2ft%-5.2ft%-5.2ft%-5.2ft%-5.2ft%-5.2ftn",stui.num,stui.name,stui.Normal_score1,stui.Normal_score2,stui.Normal_score3,stui.Period_score,stui.End_score,stui.ave1,stui.ave2,stui.ave3); printf("n");fclose(fp);printf("press enter back to the menu:n");getch();void sort_score() /*按总评成绩排序*/FILE *fp;int i,j;struct student a;for(j=0;j<n-1;j+)for(i=0;i<n-j-1;i+) if(stui.ave2>stui+1.ave2) a.num=stui.num; strcpy(a.name,stui.name); a.Normal_score1=stui.Normal_score1; a.Normal_score2=stui.Normal_score2; a.Normal_score3=stui.Normal_score3; a.Period_score=stui.Period_score; a.End_score=stui.End_score; a.ave1=stui.ave1; a.ave2=stui.ave2; a.ave3=stui.ave3; stui.num=stui+1.num; strcpy(stui.name,stui+1.name); stui.Normal_score1=stui+1.Normal_score1; stui.Normal_score2=stui+1.Normal_score2; stui.Normal_score3=stui+1.Normal_score3; stui.Period_score=stui+1.Period_score; stui.End_score=stui+1.End_score; stui.ave1=stui+1.ave1; s