2022年C语言课程设计-学生成绩管理系统 .pdf
一、问题描述能够实现对学生成绩的统计,处理二、 基本要求1) 每条记录由学号、姓名、若干门课程的成绩组成;2) 能计算每个学生的总分和平均分并显示;3)能按平均分统计各分数段的人数,并以分布图显示,如右图所示。4) 在此基础上,可进行文件操作。三、 系统分析与设计此程序所要达到的效果与具有的功能如上述要求,大致的 main 函数中要包含的几个子函数也就比较明确,首先肯定要有一个结构体的定义,然后就是子函数,比如求总分的而函数Total(),求平均分的函数Avg() ,然后就是查找,要通过一个学号返回到数组下标,然后找到学生,在显示函数中调用得到这个学生的所有信息,而统计图则简单的用一个二维数组来实现,当然考虑到实用性,另加一个学生信息修改,学生信息删除,按平均分排序的函数,使软件功能尽可能全四、 流程图I I I I I I I I I I I I I I I I I 60 70 80 90 100 开始,进入菜单选 1,添加学生信息选 2,修改 学 生选 3,删除 学 生选 4,按姓 名 查选 5,按平 均 分排序选 6,显示 分 数段 统 计图选 7,退出程序名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 1 页,共 10 页 - - - - - - - - - 五、 程序清单#include struct Student char ID20; char Name20; float Mark1; float Mark2; float Mark3; float Average; float Total; ; struct Student students100; int num=0; float Total(struct Student stu) return (stu.Mark1+stu.Mark2+stu.Mark3); float Avg(struct Student stu) return (stu.Mark1+stu.Mark2+stu.Mark3)/3; int Student_SearchByIndex(char id) int i; for (i=0;inum;i+) if (strcmp(studentsi.ID,id)=0) return i; return -1; int Student_SearchByName(char name) int i; for (i=0;inum;i+) if (strcmp(studentsi.Name,name)=0) return i; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 2 页,共 10 页 - - - - - - - - - return -1; void Student_DisplaySingle(int index) printf(%10s%10s%8s%8s%8s%10s%10sn,xuehao,name,mark1,mark2,mark3,average,total); printf(-n); printf(%10s%10s%8.2f%8.2f%8.2f%10.2f%10.2fn,studentsindex.ID,studentsindex.Name, studentsindex.Mark1,studentsindex.Mark2,studentsindex.Mark3,studentsindex.Average,studentsindex.Total); void Student_Insert() while(1) printf(please input xuehao:); scanf(%s,&studentsnum.ID); getchar(); printf(please input name:); scanf(%s,&studentsnum.Name); getchar(); printf(please input Mark1:); scanf(%f,&studentsnum.Mark1); getchar(); printf(please input Mark2:); scanf(%f,&studentsnum.Mark2); getchar(); printf(please input mark3:); scanf(%f,&studentsnum.Mark3); getchar(); studentsnum.Total=Total(studentsnum); studentsnum.A verage=Avg(studentsnum); num+; printf(go on?(y/n); if (getchar()=n) break; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 3 页,共 10 页 - - - - - - - - - void Student_Modify() float mark1,mark2,mark3; while(1) char id20; int index; printf(please input the xuehao of the student you want tochange:);scanf(%s,&id); getchar(); index=Student_SearchByIndex(id); if (index=-1) printf(this student is not here!n); else printf(the information of the student you want to change is:n); Student_DisplaySingle(index); printf(- please input the new things-n); printf(please input xuehao:); scanf(%s,&studentsindex.ID); getchar(); printf(please input name:); scanf(%s,&studentsindex.Name); getchar(); printf(please input mark1:); scanf(%f,&studentsindex.Mark1); getchar(); printf(please input mark2:); scanf(%f,&studentsindex.Mark2); getchar(); printf(please input mark3:); scanf(%f,&studentsindex.Mark3); getchar(); studentsindex.A verage=Avg(studentsindex); printf(go on?(y/n); if (getchar()=n) break; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 4 页,共 10 页 - - - - - - - - - void Student_Delete() int i; while(1) char id20; int index; printf(please input the xuehao of the student you want to delete:); scanf(%s,&id); getchar(); index=Student_SearchByIndex(id); if (index=-1) printf(this student is not here!n); else printf(the information of the student you want to delete is:n); Student_DisplaySingle(index); printf(are you sure?(y/n); if (getchar()=y) for (i=index;inum-1;i+) studentsi=studentsi+1; num-; getchar(); printf(go on?(y/n); if (getchar()=n) break; void Student_Select() while(1) char name20; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 5 页,共 10 页 - - - - - - - - - int index; printf(pleasse input the name of the student you want to search:);scanf(%s,&name); getchar(); index=Student_SearchByName(name); if (index=-1) printf(this student is not here!n); else printf(the information of the student you want to search is:n); Student_DisplaySingle(index); printf(go on?(y/n); if (getchar()=n) break; void Student_SortByA verage() int i,j; struct Student tmp; for (i=0;inum;i+) for (j=1;jnum-i;j+) if (studentsj-1.A veragestudentsj.A verage) tmp=studentsj-1; studentsj-1=studentsj; studentsj=tmp; void Student_Display() int i; printf(%10s%10s%8s%8s%8s%10sn,xuehao,name,mark1,mark2,mark3,average);名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 6 页,共 10 页 - - - - - - - - - printf(-n); for (i=0;inum;i+) printf(%10s%10s%8.2f%8.2f%8.2f%10.2fn,studentsi.ID,studentsi.Name, studentsi.Mark1,studentsi.Mark2,studentsi.Mark3,studentsi.Average); void IO_ReadInfo() FILE *fp; int i; if (fp=fopen(Database.txt,rb)=NULL) printf(can not open the file!n); return; if (fread(&num,sizeof(int),1,fp)!=1) num=-1; else for(i=0;inum;i+) fread(&studentsi,sizeof(struct Student),1,fp); fclose(fp); void IO_WriteInfo() FILE *fp; int i; if (fp=fopen(Database.txt,wb)=NULL) printf(can not open the file!n); return; if (fwrite(&num,sizeof(int),1,fp)!=1) printf(write in the wrong file!n); for (i=0;inum;i+) 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 7 页,共 10 页 - - - - - - - - - if (fwrite(&studentsi,sizeof(struct Student),1,fp)!=1) printf(write in the wrong file!n); fclose(fp); void Student_Tu() char str580=,6,0,7,0,8,0,9,0,1,0,0; int R,i,j=0,k=0,p=0,q=0,r=0; for(i=0;inum;i+) R=studentsi.A verage/10; switch(R) case 0: case 1: case 2: case 3: case 4: case 5: str0j+4=*;j+;break; case 6: str1k+4=*;k+;break; case 7: str2p+4=*;p+;break; case 8: str3q+4=*;q+;break; case 9: case 10: str4r+4=*;r+;break; default:break; for(i=0;i5;i+) for(j=0;j80;j+) printf(%c,strij); main() int choice; IO_ReadInfo(); while(1) printf(n- Management System of students information-n); printf(1. Increase students recordsn); printf(2.Modify student recordsn); printf(3. Delete the student recordsn); 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 8 页,共 10 页 - - - - - - - - - printf(4. According to the students name queryn); printf(5. According to the average scoresn); printf(6. Xian shi tun); printf(7. exitn); printf(Please select(1-7):); scanf(%d,&choice); getchar(); switch(choice) case 1: Student_Insert();break; case 2: Student_Modify();break; case 3: Student_Delete();break; case 4: Student_Select();break; case 5: Student_SortByAverage();Student_Display();break; case 6: Student_Tu();break; case 7: exit();break; IO_WriteInfo(); 六、 测试数据进入菜单界面,选择 1,输入学号 001,姓名 zhang, 输入分数 56,56,54,选择继续,则002,liu,25,45,56,选择 n返回菜单选择 4 输入 zhang显示选 n 返回菜单,选 2,输入 001显示输入新学号 003,新成绩 56,45,87 选 n 返回菜单选 5 显示如下:名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 9 页,共 10 页 - - - - - - - - - 返回菜单选 6 显示如下:选择 3,输入 003,显示选 y,y 输入 003 显示:选 n,返回菜单,再选5 显示:返回菜单,选 7 退出八、小结及收获和体会程序的设计要分析清楚程序的功能, 用处, 做到对要做的程序有一定预测,然后着手开始做,在做程序的过程当要熟练的运用TC软件来运行,会遇到大大小小的不同的问题, 有可能是一处小错误而导致整个程序显示很多报错,这就要求我们在做程序的过程当中一定要仔细,程序的编写难免会遇到自己能力范围外的困难,需要我们虚心的请教别的同学,老师,或者去查询各种资料文献,来完成自己的程序。九、参考书目1谭浩强, C程序设计教程,清华大学出版社,2007 年2赵永哲,李雄飞,戴秀英编著,C 语言程序设计 ,科学出版社,2003 年3夏宽理,赵子正编著, C 语言程序设计 ,中国铁道出版社,2006 年4谭浩强编著, C 程序设计,清华大学出版社,1991 年5Gary J. Bronson, A First Book of ANSI C (Fourth Edition), Publishing House of Electronics Industry, 2006. 6Al Kelley, Ira Pohl, A Book on C: Programming in C (Fourth Edition), China Machine Press, 2004. 7Brian W. Kernighan, Dennis M. Ritchie, The C Programming Language, China Machine Press, 2006. 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 10 页,共 10 页 - - - - - - - - -