1、c语言课程设计报告书学生成绩管理C 语言程序设计报告课题:学生成绩管理 时间:2010/7/15一、需求分析任务要求:自学C语言中有关链表及外部文件的内容,设计出学生成绩管理。具体要求如下:1.主要功能:(1)能按学期、按班级完成对学生成绩的录入、修改(2)能按班级统计学生的成绩,求学生的总分及平均分,并能根据学生的平均成绩进行排序(3)能查询学生成绩,不及格科目及学生名单(4)能按班级输出学生的成绩单系统功能需求分析:1、定义一个结构体类型,成员包括学期、班级、各科成绩、建立链表,定义该结构体类型的指针,用于指向各结点; 2、分别建立具有添输入、修改、查询、总分及平均分、排序等功能的子函数,
2、完成相应功能,对程序实现模块化。二、概要设计系统总体设计框架: 对程序进行模块化,建立输入、修改、查询、查找和显示功能的子函数,各子函数中运用链表存储数据。系统功能模块图:三、详细设计主要功能模块的算法设计思路如下:1、输入信息函数(1)定义指向结构体变量的指针;(2)移动指针,找到插入结点;(3)在要插入的结点输入信息;(4)返回头指针。2、修改信息(1)定义指向结构体变量的指针;(2)用指针检验链表中是否有记录,若没记录,出现报错,然后要求重新输入;(3)根据要修改的编号查找对应结点;(4)修改信息;(5)修改成功。3、排序函数(1)定义所要排序的班级和链表的头指针为形参;(2)调用排序函
3、数,把班级和链表的头指针赋给形参;(3)在子函数中进行排序;(4)输出排序结果。4、显示学生成绩信息(void Disp(Link l))(1)选择想要查询的项目(学生各科成绩、不及格科目、班级成员);(2)用指针检验是否有记录;(3)若无记录,输出提示信息,返回主函数;若有记录,移动指针,依次输出记录;5、查询班级成绩信息(void Find(Link l))(1)选择所要查询的班级;(2)输入班级:(3)在链表中寻找相应结点;(4)输出结点信息。以上各个函数的流程图如下: 主函数定义程序所需变量调用CREAT函数创建一个信息链表并返回指针继续进行操作1、修改信息2、统计成绩并排序3、查找信
4、息4、输出成绩输入所需修改学生的姓名输入班级查询分数查询科目查询班级输入班级序号调用add并赋值给P-sum查找班内成员调用average函数输入姓名并查找学生输出不及格学生的姓名及成绩输入班级序号并输出班级成员的名字逐个输出他们的各科成绩并赋值给P-ave输出排序前的学生成绩调用sort 进行排序输出排序后的学生成绩是否继续操作子函数排序:f!=p-classp=p-nextf=r-classf=s-next-class&s-next交换结构体内各成员的值求和:int sumi=p-classyesnosum=p-scor_1+ p-scor_2+ p-scor_3return(sum)求平
5、均数:float aveint sum sum=add(I,P)ave=sum/3.0return (ave)四、主要源程序代码#include #include #include #define NULL 0#define LEN sizeof (struct student)#define PRINT printf(=main menu=n)#define PRIN printf(Please chose the number:n)#define PRI printf(Sorry,the number you chose is error,please chose againn)struc
6、t student *定义一个结构体* int term; *学期* int class; *班级* char name20; *姓名* int score_1; *科目一* int score_2; *科目二* int score_3; *科目三* float ave; *平均分* int sum; *总分* struct student *next;int n;struct student *creat(void) *创建信息链表* struct student *head; struct student *p1,*p2; n=0; p1=p2=(struct student *)mall
7、oc(LEN); printf(Please input the student information:n); printf(Term Class Name Score_1 Score_2 Score_3n); scanf(%d%d%s%d%d%d,&p1-term,&p1-class,p1-name,&p1-score_1,&p1-score_2,&p1-score_3); head=NULL; while(p1-term!=0) n=n+1; if(n=1) head=p1; else p2-next=p1; p2=p1; p1=(struct student *) malloc(LEN
8、); scanf(%d%d%s%d%d%d,&p1-term,&p1-class,p1-name,&p1-score_1,&p1-score_2,&p1-score_3); p2-next=NULL; return(head);void sort(struct student *p,int f) *排序(形参为链表的头指针和想要排序的班级)* int a,b,c,e; float d; char z20; struct student *r,*s; while(f!=p-class) *判断是否是想要排序的班级* p=p-next; for(r=p;f=p-class&r;r=r-next)
9、for(s=p;s-next&f=s-next-class;s=s-next) if(s-avenext)-ave) *交换结构体各个成员* d=s-ave; s-ave=s-next-ave; s-next-ave=d; a=s-score_1; s-score_1=s-next-score_1; s-next-score_1=a; b=s-score_2; s-score_2=s-next-score_2; s-next-score_2=b; c=s-score_3; s-score_3=s-next-score_3; s-next-score_3=c; e=s-sum; s-sum=s-
10、next-sum; s-next-sum=e; strcpy(z,s-name); strcpy(s-name,s-next-name); strcpy(s-next-name,z); int add(int i,struct student *p) *求和(形参为想要求和的班级和链表的头指针)* int sum; if(i=p-class) sum=p-score_1+p-score_2+p-score_3; return(sum);float average(int i,struct student *p) *求平均分(形参为想要求和的班级和链表的头指针)* float ave; int
11、sum; sum=add(i,p); *调用add函数求和* ave=sum/3.0; return(ave);void main() *主函数* int i,m; struct student *p,*q; printf(=Now begin to set up=n); p=creat(); *调用creat函数,并创建一个信息链表* q=p; do PRINT; printf( 1:correct the student informationn); *修改学生信息* printf( 2:calculate the students score and then sortn); *统计学生
12、成绩并排序* printf( 3:search the students informationn); *查找学生信息* printf( 4:output the score of studentn); *输出学生成绩* PRIN; do scanf(%d,&i); if(i!=1&i!=2&i!=3&i!=4) PRI; *报错功能* while(i!=1&i!=2&i!=3&i!=4); if(i=1) char x20; printf(Please input the name of student you want to correct:); do scanf(%s,x); *输入你要
13、修改学生成绩的姓名* for(p=q;p!=NULL;p=p-next) if(strcmp(x, p-name)=0) *查找学生* printf(Now,please input the new score of the student:n); *输入新的成绩* printf(Score_1 Score_2 Score_3n); scanf(%d%d%d,&p-score_1,&p-score_2,&p-score_3); printf(Information correct succeedn); printf(Now,%ss score is %-6d%-6d%-6dn,x,p-scor
14、e_1,p-score_2,p-score_3); break; if(p=NULL) printf(Cant find the student,please input again:); * 报错功能* while(p=NULL); p=q; if(i=2) int j; printf(Please input which class you want to count:); scanf(%d,&j); *输入你想要统计的班级* printf(The score information of %d class is:n,j); printf(Name Score_1 Score_2 Scor
15、e_3 Average Sumn); for(p=q;p!=NULL;p=p-next) p-sum=add(j,p); * 调用函数add并赋值给结构体* p-ave=average(j,p); *调用函数average并赋值给结构体* p=q; printf(Before sorted,the student score is:n); for(p=q;p!=NULL;p=p-next) if(j=p-class) printf(%-9s%-9d%-9d%-9d%-9.2f%-9dn,p-name,p-score_1,p-score_2,p-score_3,p-ave,p-sum); *输出
16、排序前的学生成绩* p=q; sort(p,j); *调用函数sort* printf(After sorted,the student score is:n); for(p=q;p!=NULL;p=p-next) if(j=p-class) printf(%-9s%-9d%-9d%-9d%-9.2f%-9dn,p-name,p-score_1,p-score_2,p-score_3,p-ave,p-sum); *输出排序后的成绩* p=q; if(i=3) int a; char y20; PRINT; printf( 1:search the score of studentn); *查询
17、学生的各科分数* printf( 2:search the score of fail lessonn); *查询不及格科目* printf( 3:search the name of studentn); *查询每个班级的成员* printf(Whats do you want to do?); PRIN; scanf(%d,&a); *输入你想要执行的操作的序号* if(a=1) printf(Please input the student name:); do scanf(%s,y); *输入你想要查询的学生的姓名* for(p=q;p!=NULL;p=p-next) if(strcm
18、p(y,p-name)=0) *查找学生* printf(%ss score is %d %d %dn,p-name,p-score_1,p-score_2,p-score_3); break; *输出学生的成绩* if(p=NULL) printf(Cant find the student,please input again:); *报错功能* while(p=NULL); p=q; else if(a=2) for(p=q;p!=NULL;p=p-next) if(p-score_1name,p-score_1); if(p-score_2name,p-score_2); if(p-s
19、core_3name,p-score_3); p=q; else if(a=3) int c; printf(Please input the number of class:n); scanf(%d,&c); *输入你想要输出成绩的班级* printf(The %d class have these student:n,c); for(p=q;p!=NULL;p=p-next) if(c=p-class) printf(%-10s,p-name); printf(n); p=q; if(i=4) int b; printf(Please input which class:n); *输入你想
20、要输出成绩的班级* scanf(%d,&b); printf(Now,the score of the student of %d class is:n,b); printf(Name Score_1 Score_2 Score_3n); for(p=q;p!=NULL;p=p-next) if(b=p-class) printf(%-12s%-12d%-12d%-12dn,p-name,p-score_1,p-score_2,p-score_3); 输出成绩 PRINT; printf(Do you want to going on?n); *是否想要继续操作* printf( 1:YES
21、2:NO n); scanf(%d,&m); while(m!=2);_五、调试分析过程描述运行情况如下:输入学生的基本信息:修改指定学生的成绩:统计并排序一班成绩:统计并排序二班的成绩:查询指定学生的成绩:查询学生不及格的成绩:查询班级成员:输出一班的成绩:输出二班的成绩:调试过程中的主要问题及解决方法:1、执行排序函数时出错,指针指向不确定。2、编译时无出错警告,连接时出现错误。3、表格输出时,格式不能对齐。未运用格式控制字符。六、课程设计小结通过这次课程设计,我对C语言有了更深刻的了解,增强了程序的编写能力,巩固了专业知识,对程序的模块化观念也又模糊逐渐变的清晰了。在程序的运行与调试过程中出现了很多错误,通过反复地复习课本上的相关知识,不停地修改与调试,我终于完成了这段程序。在调试过程中,我认识到了C语言的灵活性与严谨性,同一个功能可以由不同的语句来实现,但编写程序时要特别注意细节方面的问题,因为一个小小的疏忽就能导致整个程序不能运行。当然我也认识到了自己的薄弱之处,如对链表相关知识的欠缺,文件运用的不熟练,在以后的学习中我要集中精力、端正态度,争取把知识学得更扎实、更全面。
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1