




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、/*学生成绩管理系统 数据库的数据项主要数据包括:学号、姓名、年级、专业、成绩1、成绩 2、成绩 3、平均成绩、总成绩。要求具有以下功能:(1) 添加、删除任意个记录。(2) 修改任意个记录。(3) 显示、保存记录。(4) 排序功能:打开学生数据库,计算每个学生的平均成绩和总成绩,用冒泡法或选择排 序法将平均成绩和总成绩排序后生成两个新文件(从大到小) ,存盘并显示这两个文件的全部记录。(5) 查询功能:打开总成绩排序文件,用折半查找法统计出给定分数的人数并显示。要求: (1)设计一个主函数和多个子函数,每个子函数完成一个相对独立的子功能。 (2)程序运行时,首先进行口令检查,再显示菜单。并能
2、根据菜单调用相应的函数功能。口令程序段的功能要求: 1提示用户输入一个口令。 2用户输入口令后,若口令对,则提示用户通过,可执行后续程序;否则不通过。 3可对用户的口令输入进行次数限制(如:重复输入3 次都不对),则自动退出系统。 */#include#include#include struct studentint num;char name10;int grade;char major10;float score_1,score_2,score_3,aver,total;struct student *next;struct student *creat(void);struct stu
3、dent *add(void);struct student *del(int num);struct student *alter();void save(struct student *head);void read();void totalsort(struct student *head);void aversort(struct student *head);void Bfindsort();int all=0;void main()int i,n,m,num;char ord10=student,ord_110;struct student *p;for(i=0;i=3;i+)if
4、(i=3)exit(0);printf( 请第 %d 次输入进入系统的指令 :,i+1); scanf(%s,ord_1);if(strcmp(ord,ord_1)!=0)printf( 输入的指令有误请重新输入。 n); if(strcmp(ord,ord_1)=0)break;p=NULL;Ioop_2:printf(”输入系统的功能:nO、建立一个数据库;n1、添加与保存学生数据;n2、删 除与保存学生数据;n3、修改与保存学生数据;n4、显示数据库的记录;n5、将数据进 行排序;n6、查询指定成绩的人数:”);Ioop: scanf(%d,&n);if(n6)printf(n 输入的选
5、择有误请重新输入 :);goto Ioop;if(n=2)printf( 输入删除学生数据的学号 :);scanf(%d,&num);switch(n) case0:p=creat();save(p);read();break; case1:p=add();save(p);read();break; case2:p=deI(num);save(p);read();break;case3:p=aIter();save(p);read();break;case4:read();break;case 5 :printf( 输入选择排序的功能 1、根据平均成绩; 2、根据总成绩 :);Ioop_1:
6、scanf(%d,&m); if(m2)printf(n 输入的选择有误请重新输入 :); goto Ioop_1;switch(m)case1:aversort(p);break;case2:totalsort(p);break;break; case6:Bfindsort();break;loop_5: printf( 输入你要进行的步骤: 1、返回上一菜单菜单; 2、退出程序。 n);scanf(%d,&n);if(n2)printf( 输入的选择有误,请重新输入 :); goto loop_5;switch(n)case 1:goto loop_2;break; case2:break
7、;struct student *creat(void)int i,n;struct student *head,*p,*q,*tail; printf( 输入学生的个数 :); scanf(%d,&n);head=NULL; for(i=0;inext=p;tail=p; p-next=NULL;q=head;printf( 输入学生的学号、名字、年级、专业、三门成绩 :);scanf(%d %s %d %s %f %f %f,&p-num,&p-name,&p-grade,&p-major,&p- score_1,&p-score_2,&p-score_3);loop: while(q-n
8、ext!=NULL) if(q-num=p-num) printf( 输入的学生号错误请重新输入学生学号: ); scanf(%d,&p-num);goto loop;q=q-next; p-aver=(p-score_1+p-score_2+p-score_3)/3; p-total=p-score_1+p-score_2+p-score_3;return(head);void save(struct student *head)struct student *p;FILE *fp;if(fp=fopen(student.txt,wb)=NULL) printf( 打开文件失败。 n);ex
9、it(0);p=head;while(p!=NULL)fwrite(p,sizeof(struct student),1,fp); p=p-next;fclose(fp);struct student *del(int num)int i,n=0;struct student *p,*q,*head;FILE *fp;if(all=0) printf( 数据库为空。 n); head=NULL; return(head);p=(struct student *)malloc(sizeof(struct student); if(fp=fopen(student.txt,rb)=NULL)pri
10、ntf( 打开 student.txt 文件失败 n); exit(0); for(i=0;p!=NULL;i+)p=(struct student *)malloc(sizeof(struct student); fread(p,sizeof(struct student),1,fp);if(i=0) head=p;if(num=p-num) if(p=head) head=p-next; elseq-next=p-next;n+; all-; q=p; if(n=0) printf( 没有 %d 这一学生号的学生 !n,num);return(head);struct student *a
11、dd()int i,j,m,n=0;FILE *fp;struct student *p,*q,*temp,*head,*tail; if(all=0) head=NULL; else if(fp=fopen(student.txt,rb)=NULL)printf( 打开 student.txt 文件失败 n); exit(0);p=(struct student*)malloc(sizeof(struct student); fread(p,sizeof(struct student),1,fp);head=p;tail=p;while(p-next!=NULL)p=(struct stud
12、ent*)malloc(sizeof(struct student); fread(p,sizeof(struct student),1,fp);tail-next=p;tail=p;tail-next=NULL;fclose(fp);printf( 输入需要输入学生的个数 :);scanf(%d,&j);for(i=0;inum,&p-name,&p-grade,&p-major,&p- score_1,&p-score_2,&p-score_3);temp=head;loop_1: while(temp!=NULL)if(temp-num=p-num)printf( 输入的学生号错误请重新
13、输入学生学号: ); scanf(%d,&p-num);goto loop_1;temp=temp-next;p-aver=(p-score_1+p-score_2+p-score_3)/3; p-total=p-score_1+p-score_2+p-score_3; if(head=NULL)head=p;p-next=NULL; else q=head; n=1;while(q-next!=NULL)q=q-next;n+;printf( 该链表一共有节点个数 %d。 n,n); loop: printf( 输入将数据插入第几个节点后面。 n); scanf(%d,&m);if(mn)p
14、rintf( 输入有误,请重新输入。 n);goto loop;q=head;if(m=0)p-next=head;head=p;elsewhile(m-1)!=0)q=q-next;m-;p-next=q-next;q-next=p;return(head);struct student *alter()int m,num,gra,n;char maj10,name10;float score_1,score_2,score_3;struct student *p,*q,*head;FILE *fp;if(all=0)printf( 数据库为空。 n);head=NULL;return(he
15、ad);if(fp=fopen(student.txt,rb)=NULL)printf( 打开 student.txt 文件失败 n);exit(0);p=(struct student*)malloc(sizeof(struct student);fread(p,sizeof(struct student),1,fp);head=p;q=p;loop_1:printf( 输入修改学生数据的姓名: );scanf(%s,&name);while(strcmp(name,p-name)!=0)p=p-next;if(p=NULL)printf( 没有该学生。 n);return(head);lo
16、op:printf(请选择修改学生的具体数据:n1、学号;2、年级;3、专业;n4、成绩1; 5、成绩 2; 6、成绩 3:);scanf(%d,&m);if(m6)printf(n 输入的选择有误请重新输入 :);goto loop;switch(m)case1:printf( 输入新的学号 :);loop_2:scanf(%d,&num);while(q!=NULL)if(q-num=num)goto loop_2;q=q-next;p-num=num;break;case2:printf( 输入新的年级 :);scanf(%d,&gra); p-grade=gra; break;case
17、3:printf( 输入新的专业 :);scanf(%s,&maj); strcpy(p-major,maj);break;case4:printf( 输入新的成绩 :);scanf(%f,&score_1);p-score_1=score_1; p-aver=(p- score_1+p-score_2+p-score_3)/3;p-total=p- score_1+p-score_2+p-score_3; break;case5:printf( 输入新的成绩 :);scanf(%f,&score_2);p-score_2=score_2; p-aver=(p- score_1+p-score
18、_2+p-score_3)/3;p-total=p- score_1+p-score_2+p-score_3;break;case6:printf( 输入新的成绩 :);scanf(%f,&score_3);p-score_3=score_3; p-aver=(p- score_1+p-score_2+p-score_3)/3;p-total=p- score_1+p-score_2+p-score_3;break;printf(选择你要执行的内容:n1、返回上一菜单n2、返回主菜单n3、修改另一学生 的数据 );loop_5: scanf(%d,&n);if(n3)printf( 输入的选择
19、有误,请重新输入 :);goto loop_5;switch(n)case 1 :goto loop;break;case2:break;case3:goto loop_1;break; return(head);void read()struct student *p,*head;FILE *fp;if(all=0)printf( 系统没有学生数据。 n);return; if(fp=fopen(student.txt,rb)=NULL)printf( 打开文件失败。 n);exit(0);p=(struct student*)malloc(sizeof(struct student); f
20、read(p,sizeof(struct student),1,fp);head=p;printf( 打开 student.txt 文件的学生数据。 n);printf(listnum name grade major score_1 score_2 score_3 aver totaln);while(p!=NULL) printf(student %-3d %-4s %-5d %-5s %-7.2f %-7.2f %-7.2f %-4.2f %-5.2f n, p-num,p-name,p-grade,p-major,p-score_1,p-score_2,p-score_3,p- ave
21、r,p-total);p=p-next;fclose(fp);void aversort(struct student *head)int temp;float temp_1;char temp_210;struct student *p,*q,*i;FILE *fp;p=head;while(p-next!=NULL)q=p; i=p-next; while(i!=NULL) if(i-averq-aver)q=i; i=i-next;if(q!=p) temp=p-num;p-num=q-num;q-num=temp;strcpy(temp_2,p-name);strcpy(p-name,
22、q-name);strcpy(q-name,temp_2);temp=p-grade;p-grade=q-grade;q-grade=temp;strcpy(temp_2,p-major);strcpy(p-major,q-major);strcpy(q-major,temp_2);temp_1=p-score_1;p-score_1=q-score_1;q-score_1=temp_1;temp_1=p-score_2;p-score_2=q-score_2;q-score_2=temp_1;temp_1=p-score_3;p-score_3=q-score_3;q-score_3=tem
23、p_1;temp_1=p-aver;p-aver=q-aver;q-aver=temp_1;temp_1=p-total;p-total=q-total;q-total=temp_1;p=p-next; if(fp=fopen(student_1.txt,wb+)=NULL)printf( 打开 student_1.txt 文件失败 n);exit(0);p=head;while(p!=NULL)fwrite(p,sizeof(struct student),1,fp);p=p-next;p=head;rewind(fp);printf( 读出由平均成绩排序出来的文件 student_1.tx
24、t。 n);printf(listnum name grade major score_1 score_2 score_3 aver totaln);while(p!=NULL)fread(p,sizeof(struct student),1,fp);printf(student %-3d %-4s %-5d %-5s %-7.2f %-7.2f %-7.2f %-4.2f %-5.2f n, p-num,p-name,p-grade,p-major,p-score_1,p-score_2,p-score_3,p-aver,p-total);fclose(fp);void totalsort(
25、struct student *head)int temp;float temp_1;char temp_210;struct student *p,*q,*i;FILE *fp;p=head;while(p-next!=NULL)q=p;i=p-next;while(i!=NULL)if(i-totalq-total)q=i;i=i-next;if(q!=p) temp=p-num;p-num=q-num;q-num=temp;strcpy(temp_2,p-name);strcpy(p-name,q-name);strcpy(q-name,temp_2);temp=p-grade;p-gr
26、ade=q-grade;q-grade=temp;strcpy(temp_2,p-major);strcpy(p-major,q-major);strcpy(q-major,temp_2);temp_1=p-score_1;p-score_1=q-score_1;q-score_1=temp_1;temp_1=p-score_2;p-score_2=q-score_2;q-score_2=temp_1;temp_1=p-score_3;p-score_3=q-score_3;q-score_3=temp_1;temp_1=p-aver;p-aver=q-aver;q-aver=temp_1;temp_1=p-total;p-total=q-total;q-total=temp_1; if(fp=fopen(student_1.txt,wb+)=NULL) printf( 打开 student_1.txt 文件失败 n);exit(0); p=head;while(p!=NULL)fwrite(p,sizeof(struct
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 废模板回收协议书
- 服务期承诺协议书
- 授权分公司协议书
- 车辆损失险赔偿协议书
- 工商用租赁协议书
- 签约小演员协议书
- 蛋糕店议价协议书
- 绘画材料仓储行业深度调研及发展项目商业计划书
- 滑雪胜地客运行业深度调研及发展项目商业计划书
- 高端珠宝镶嵌腕表系列企业制定与实施新质生产力项目商业计划书
- 健康管理PBL教程 课件 项目八 肥胖症的健康管理
- 机械专业面试真题及答案
- 移动营业厅合作合同协议
- 家政搬家合同协议
- 2025-2030中国核电用钢行业市场发展分析及发展趋势预测研究报告
- 口腔外科门诊手术操作规范
- 绿色施工评价标准【B.0.1 批次评价表】
- 以案释德、以案释纪、以案释法的教育心得体会
- 《公路桥梁无缝式树脂弹性体伸缩装置施工技术规程》
- 2025年吉林省中考模拟语文试卷试题及答案详解
- 呼吸内科科普知识
评论
0/150
提交评论