1、学生成绩管理学生成绩管理指导教师 李琳晧 实验时间: 2011 年 12月 1日学院 生物信息学院 专业 生物技术 实验室 S302 班级 0621001 学号 2010212471 姓名 李言 班级 0621001 学号 2010212481 姓名 谢保朋 实验题目:学生成绩管理(限最多2人完成)1.主要功能:(1)能按学期、按班级完成对学生成绩的录入、修改(2)能按班级统计学生的成绩,求学生的总分及平均分,并能根据学生的平均成绩进行排序(3)能查询学生成绩,不及格科目及学生名单(4) 能按班级输出学生的成绩单(5) 系统以菜单方式工作实验目的: 1、 熟悉结构体、链表的使用2、 熟悉指向函
2、数的指针、以及嵌套调用3、 学会规范、美观化设计程序实验要求:1.系统以菜单方式工作2.学生信息录入功能3.输出所有学生信息4.按班级输出学生信息5.对学生信息进行修改、删除6、添加学生信息7、对学生成绩进行排名8、查询不及格学生的名单和科目9、更改DOS界面的前景和背景颜色10、每次重新输入都进行一次刷屏实验主要步骤:1.定义结构体;2.建立链表存储学生信息;3.设计菜单,在主函数中实现各个功能函数;4.调试程序,找出问题,并且优化程序。代码如下:#include#include#includestruct stu int classnumber; char name20; int scor
3、e3; int sum; float average; struct stu *next;typedef struct stu STU;STU *head=NULL;char menu();void Applynode();void Addnode();void Total(STU *p);void Failpass();void studentlist();void classlist();void change();void delect();void Sort();void SortScore(int (*compare)(int a, int b);/函数功能:输出系统的主菜单,选择相
4、应的功能后链接到其他函数实现对应的功能char menu(void) char ch; printf(tt*n); printf(ttMENU:n); printf(tt1.输入学生成绩n); printf(tt2.输出所有学生成绩单n); printf(tt3.按班级输出成绩单n); printf(tt4.不及格科目及学生名单n); printf(tt5.增加一个学生信息n); printf(tt6.删除一个学生信息n); printf(tt7.修改一个学生信息n); printf(tt8.按总分实现排名n); printf(tt9.退出n); printf(tt*n); printf(nn
5、ttPlease enter your choice:); fflush(stdin); ch=getchar(); getchar(); return(ch);/创建链表,输入学生的成绩void Applynode() char c = y; while(c=Y|c=y) Addnode();/为新的数据申请一个节点 printf(Do you want to input another data?(Y/N):); scanf(%c,&c);/输入Y或者y则继续申请节点空间 system(cls); fflush(stdin);/向链表添加尾节点void Addnode() STU *p=N
6、ULL; STU *pr=head; p=(STU *)malloc(sizeof(STU); if(p=NULL) printf(File to apply the noden); exit(0); if(head=NULL) head=p; /如果头指针为空,将p置为首节点 else while(pr-next != NULL) pr=pr-next; pr-next=p; printf(Input the data.n); printf(Input the students namen); scanf(%s,p-name); printf(Input the students class
7、n); scanf(%d,&p-classnumber); printf(Input the students scoren); printf(Please input the score of Chinese:); scanf(%d,p-score+0); printf(Please input the score of English:); scanf(%d,p-score+1); printf(Please input the score of Math:); scanf(%d,p-score+2); Total(p); p-next=NULL; fflush(stdin);/计算每个学
8、生成绩的总分和平均分void Total(STU *p) int i; p-sum=0; for(i=0;isum+=p-scorei; p-average=(float)p-sum/3;/删除一个学生信息void delect() STU *p=head; STU *front,*current; char Name20; printf(Please input the students name:); scanf(%s,Name); if(p=NULL) printf(This is an empty list!n); else if(strcmp(head-name,Name)=0)/判
9、定删除对象是否为表头 front=head; head=head-next; free(front); else front=head; current=head-next; while(current!=NULL&strcmp(current-name,Name)!=0) front=current; current=current-next; if(current!=NULL) front-next=current-next; free(current); else printf(Cant find the student!n); /修改一个学生的信息void change() STU *
10、p=head; char Name20; printf(Please input the students name:); scanf(%s,Name); while(p!=NULL&strcmp(p-name,Name)!=0) p=p-next; if(p!=NULL) printf(input classnumber:); scanf(%d,&p-classnumber); printf(input the score:); printf(Input the score of Chinese:); scanf(%d,p-score+0); printf(Input the score o
11、f English:); scanf(%d,p-score+1); printf(Input the score of Math:); scanf(%d,p-score+2); else printf(The name dont exist!n);/输出不及格科目及学生名单void Failpass() STU *p=head; int i=0,j=0,k=0; char str100=0,s4=*; strcat(str,Classnumber Name Chinese English Math); if(p=NULL) printf(This is an empty list!n); el
12、se while(p) for(i=0,j=0;iscoreinext; p=head; if(k=0)/k值为0,则没有挂科人数,否则打印表头,输出挂科名单 printf(nttCongratuation!All pass the exam!n); else printf(%sn,str); while(p) for(i=0,j=0;iscoreiclassnumber,p-name); for(i=0;iscoreiscorei); else printf(%7s,s); printf(n); p=p-next; /输出所有学生成绩名单void studentlist() STU *p=h
13、ead; char str100=0; strcat(str,classnumber name ); strcat(str,Chinese English Math ); strcat(str,Sum Average); if(p=NULL) printf(Its an empty list!); else printf(%sn,str); while(p!=NULL) printf(%3d t%10s,p-classnumber,p-name); printf(%8d%8d%8d,p-score0,p-score1,p-score2); printf(%6d %6.2f,p-sum,p-av
14、erage); printf(n); p=p-next; /按照班级输出成绩单void classlist() STU *p=head; int num,i=0; char str100=0; strcat(str,name ); strcat(str,Chinese English Math ); strcat(str,sum Average); printf(Please input the class number you want to search:); scanf(%d,&num); if(head=NULL) printf(This is an empty list!); els
15、e while(p!=NULL) if(p-classnumber=num) i+;/用来标记,确定学生链表中是否存在你想要查找的班级 p=p-next; p=head; if(i!=0)/若为0,则你想查找的班级不存在 printf(%sn,str); while(p!=NULL) if(p-classnumber=num) printf(%s,p-name); printf(%8d%8d%8d%5d,p-score0,p-score1,p-score2,p-sum); printf(%7.2fn,p-average); p=p-next; else printf(Can not find
16、the score of Class %dn,num); /决定数据是否按升序排序,ab为真,则按升序排序int Ascending(int a, int b) return a b为真,则按降序排序 int Descending(int a, int b) return a b;/交换两个整型数void IntSwap(int *pt1, int *pt2) int temp; temp = *pt1; *pt1 = *pt2; *pt2 = temp;/*交换两个实型数*/void FloatSwap(float *pt1, float *pt2) float temp; temp = *
17、pt1; *pt1 = *pt2; *pt2 = temp;/*交换两个字符串*/void CharSwap(char *pt1, char *pt2) char temp15; strcpy(temp, pt1); strcpy(pt1, pt2); strcpy(pt2, temp);/ 用交换法按总成绩由高到低排序 void SortScore(int (*compare)(int a, int b) STU *pt; int flag = 0, i; do flag = 0 ; pt = head; if(head=NULL) printf(This is an empty list!
18、n); else while (pt-next != NULL) if (*compare)(pt-next-sum, pt-sum) IntSwap(&pt-classnumber, &pt-next-classnumber); CharSwap(pt-name, pt-next-name); for (i=0; iscorei, &pt-next-scorei); IntSwap(&pt-sum, &pt-next-sum); FloatSwap(&pt-average, &pt-next-average); flag = 1; pt = pt-next; puts(after Sorte
19、d:n); pt=head; studentlist(); while(flag);/学生成绩排序void Sort() char choice; printf(please input your choice:1-Ascending,2-Descending); choice=getchar(); getchar(); switch(choice) case 1:SortScore(Ascending); break; default:SortScore(Descending); break; void main() STU *p=NULL; char ch; system(COLOR 5B
20、); while(1) ch = menu(); switch(ch) case 1: system(cls); Applynode();/成绩输入模块 break; case 2: system(cls); studentlist();/查询所有学生成绩单 system(pause); system(cls); break; case 3: system(cls); classlist();/按班级查询学生成绩单 system(pause); system(cls); break; case 4: system(cls); Failpass();/输出不及格科目及学生名单 system(pa
21、use); system(cls); break; case 5: system(cls); Addnode();/增加输入一个学生信息 system(pause); system(cls); break; case 6: system(cls); delect();/删除一个学生信息 system(pause); system(cls); break; case 7: system(cls); change();/修改一个学生信息 system(pause); system(cls); break; case 8: system(cls); Sort();/排序 system(pause); system(cls); break; case 9: exit(0);/退出 break; default: system(cls); printf(Error!Please input your choice again!n); system(pause); system(cls); break; 心得体会:1. 哪些地方该加“”,自己必须要细心,及时打上。不然面对庞大的代码要查找起来比较难;2. 程序要规范化,让操作人员看起来比较美观3. 指向函数的指针用起来比较生疏,还要多熟悉
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1