




已阅读5页,还剩19页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
实验二学生管理系统学生数据信息包括:学号、性别、姓名、年龄、联系电话、三门课程成绩(数学、英语、计算机)。设计一个系统,要求:(1) 以链表形式存储信息(2) 有操作界面(3) 实现常用操作:插入、修改、删除、排序输出、查找分数段内学生信息,并统计个数程序代码:#include#include#include#includeFILE *f;struct stuint ID;char *name;char *sex;char *phone;int age;struct scorefloat math;float english;float computer;score;struct stu *next;struct TempStuint id;char name20;char sex3;char phone13;int age;struct scorefloat math;float english;float computer;score;void open(stu *head,stu *end)struct stu *p=head;if(f=fopen(studate1,rb)=NULL)cout文件打开失败!;exit(0);TempStu st;while(!feof(f)/读出数据并从结构体TemStu中拷贝到stu中int n = fread(&st,sizeof(st),1,f);if(nnext=new struct stu;p-next-name=new charstrlen()+1;strcpy(p-next-name,);p-next-sex=new charstrlen(st.sex)+1;strcpy(p-next-sex,st.sex);p-next-phone=new charstrlen(st.phone)+1;strcpy(p-next-phone,st.phone);p-next-ID=st.id;p-next-age=st.age;p-next-score.math=st.score.math;p-next-score.english=st.score.english;puter=puter;p-next-next=NULL;p=p-next;fclose(f);struct stu *putin(stu *head,stu *end)/分配新节点并初始化struct stu *p=new struct stu;char a330;coutp-ID;if(!(p-ID) cout学号不能为零,请重新输入:;else break;while(1);couta0;p-name=new charstrlen(a0)+1;strcpy(p-name,a0);couta1;p-phone=new charstrlen(a1)+1;strcpy(p-phone,a1);couta2;p-sex=new charstrlen(a2)+1;strcpy(p-sex,a2);coutp-age;if(p-ageage25) cout年龄范围不能超出18-25,请重新输入:;else break;while(1);coutp-score.math;if(p-score.mathscore.math100)cout任何一门成绩必须不低于0分,不高于100分,请重新输入:;else break;while(1);coutp-score.english;if(p-score.englishscore.english100)cout任何一门成绩必须不低于0分,不高于100分,请重新输入:;else break;while(1);puter;if(puter100)coutnext=NULL;return p;struct stu *find(stu *head,stu *end)struct stu*p=NULL;char a;int b;char c15;cout1.按姓名查找2.按学号查找endla;if(a!=1&a!=2) cout输入错误,请重新选择:;else break;while(1);if(a=1)coutc;for(p=head;p-next!=NULL;)if(strcmp(p-next-name,c)=0)break;else p=p-next;if(a=2)coutb;for(p=head;p-next!=NULL;)if(p-next-ID=b)break;else p=p-next;if(p-next=NULL) cout没有找到符合条件的节点!endl;return p;void insertfirst(stu *head,stu *end)int b,i;struct stu *p=NULL;coutb;for(i=0;inext=NULL)head-next=p;elsep-next=head-next;head-next=p;void insertend(stu *head,stu *end)int b,i;struct stu *p=NULL;coutb;for(i=0;inext=p;end=end-next;void insertB(stu *head,stu *end)int b,i;struct stu*q=NULL,*p=NULL;char c;coutb;for(i=0;inext!=NULL)cout1.在该节点之前插入2.在该节点之后插入endlc;if(c!=1&c!=2) coutnext=q-next;q-next=p;if(c=2)p-next=q-next-next;q-next-next=p;break;while(1);void insert(stu* head,stu *end)char a,c,b10;coutb;if(strcmp(b,123456)=0)cout1.插入到第一个位置2.插入到尾部3.在某人或某学号之前或之后endl;couta;if(a!=1&a!=2&a!=3)cout输入错误,请重新选择:;elseswitch(a)case 1:insertfirst(head,end);break;case 2:insertend(head,end);break;case 3:insertB(head,end);default :break;break;while(1);break;else coutc;if(c!=y) break;while(1);void revise1(struct stu *p)int a;couta;if(!a) coutnext-ID=a;break;while(1);void revise2(struct stu *p)char a20;couta;if(strlen(a)=0) coutnext-name,a);break;while(1);void revise3(struct stu *p)char a3;couta;if(strlen(a)=0) coutnext-sex,a);break;while(1);void revise4(struct stu *p)coutp-next-age;if(p-next-agenext-age25) cout年龄范围不能超出18-25,请重新输入:;else break;while(1);void revise5(struct stu *p)coutp-next-score.math;if(p-next-score.mathnext-score.math100) cout任何一门成绩必须不低于0分,不高于100分,请重新输入:;else break;while(1);void revise6(struct stu *p)coutp-next-score.english;if(p-next-score.englishnext-score.english100) cout任何一门成绩必须不低于0分,不高于100分,请重新输入:;else break;while(1);void revise7(struct stu *p)puter;if(puter100)cout任何一门成绩必须不低于0分,不高于100分,请重新输入:;else break;while(1);void revise8(struct stu *p)char a13;couta;strcpy(p-next-phone,a);void putout1()cout.setf(ios:left);cout.width(13);cout 学号;cout.width(13);cout 姓名;cout.width(15);cout联系电话;cout.width(8);cout 性别;cout.width(8);cout 年龄;cout.width(8);cout 高数;cout.width(8);cout 英语;cout.width(3);cout 计算机endl;void putout2(struct stu *p)cout.setf(ios:left);cout.width(12);cout next-ID;cout.width(14);cout next-name;cout.width(17);coutnext-phone; cout.width(7);cout next-sex;cout.width(8);cout next-age;cout.width(8);cout next-score.math;cout.width(9);cout next-score.english;cout.width(3);cout puterendl;void revise(stu *head,stu *end)struct stu *p=NULL;char b,c,d10;int i;coutd;if(strcmp(d,123456)=0)break;elsecoutc;if(c!=y) break;while(1);for(i=0;i+)p=find(head,end);if(p-next!=NULL)cout该节点当前信息如下:endl;putout1();putout2(p);cout1.修改学号2.修改姓名3.修改性别4.修改年龄;cout5.修改高数成绩6.修改英语成绩7.修改计算机成绩8.修改联系电话endlb;if(b8) cout输入错误,请重新选择:;elseswitch(b)case 1: revise1(p);break;case 2: revise2(p);break;case 3: revise3(p);break;case 4: revise4(p);break;case 5: revise5(p);break;case 6: revise6(p);break;case 7: revise7(p);break;case 8: revise8(p);default : break;break;while(1);coutc;if(c!=y) break;void del(stu *head,stu *end)struct stu *p=NULL,*q=NULL;char a,b,d10;coutd;if(strcmp(d,123456)=0)for(;)p=find(head,end);if(p-next!=NULL)cout该节点信息如下:endl;putout1();putout2(p);couta;if(a=y) q=p-next-next;delete p-next-name;delete p-next-phone;delete p-next-sex;delete p-next;p-next=q;else cout删除取消;coutb;if(b!=y) break;break;elsecouta;if(a!=y) break;while(1);void del_all(stu *head,stu *end)char a10,b;struct stu *p,*q;couta;if(strcmp(a,123456)=0)while(head-next!=NULL)p=head-next;q=head-next-next;delete p-name;delete p-phone;delete p-sex;delete p;head-next=q;break;elsecoutb;if(b!=y) break;while(1);void sortID(stu *head,stu *end)struct stu* p,*q,*r,*s;for(p=head;p-next!=NULL;)r=p;for(q=p-next;q-next!=NULL;)/如果有节点的ID小于r-next的ID,就把该节点前面的节点地址付给rif(r-next-ID)(q-next-ID)r=q;q=q-next;if(r!=p)s=r-next-next;r-next-next=p-next;p-next=r-next;r-next=s;p=p-next;void sortage(stu *head,stu *end)struct stu* p,*q,*r,*s;for(p=head;p-next!=NULL;)r=p;for(q=p-next;q-next!=NULL;)/如果有节点的age小于r-next的age,就把该节点前面的节点地址付给rif(r-next-ageq-next-age)r=q;q=q-next;if(r!=p)s=r-next-next;r-next-next=p-next;p-next=r-next;r-next=s;p=p-next;void sortmath(stu *head,stu *end)struct stu *p;struct stu *q;struct stu *r;struct stu *s;for(p=head;p-next!=NULL;)r=p;for(q=p-next;q-next!=NULL;)/如果有节点的数学成绩小于r-next的数学成绩,就把该节点前面的节点地址付给rif(r-next-score.mathq-next-score.math)r=q;q=q-next;if(r!=p)s=r-next-next;r-next-next=p-next;p-next=r-next;r-next=s;p=p-next;void sortenglish(stu *head,stu *end)struct stu* p,*q,*r,*s;for(p=head;p-next!=NULL;)r=p;for(q=p-next;q-next!=NULL;)/如果有节点的英语成绩小于r-next的英语成绩,就把该节点前面的节点地址付给rif(r-next-score.englishq-next-score.english)r=q;q=q-next;if(r!=p)s=r-next-next;r-next-next=p-next;p-next=r-next;r-next=s;p=p-next;void sortcomputer(stu *head,stu *end)struct stu* p,*q,*r,*s;for(p=head;p-next!=NULL;)r=p;for(q=p-next;q-next!=NULL;)/如果有节点的计算机成绩小于r-next的计算机成绩,就把该节点前面的节点地址付给rif(puter)r=q;q=q-next;if(r!=p)s=r-next-next;r-next-next=p-next;p-next=r-next;r-next=s;p=p-next;void putall(stu *head,stu *end)struct stu *p;putout1();for(p=head;p-next!=NULL;)putout2(p);p=p-next;void sort(stu *head,stu *end)char a;cout1.按学号排序 2.按年龄排序3.按数学成绩排序 4.按英语成绩排序 5.按计算机成绩排序endla;if(a5)cout输入错误,请重新选择:;elseswitch(a)case 1:sortID(head,end);break;case 2:sortage(head,end);break;case 3:sortmath(head,end);break;case 4:sortenglish(head,end);break;case 5:sortcomputer(head,end);default :break;break;while(1);putall(head,end);void checkmath(stu *head,stu *end)int a,b,c=0;struct stu *p;couta;cinb;putout1();for(p=head;p-next!=NULL;)if(p-next-score.math=a&p-next-score.mathnext;if(c=0)cout对不起,没有查找到符合条件的节点!endl;else cout共有c条符合条件的节点.;void checkenglish(stu *head,stu *end)int a,b,c=0;struct stu *p;couta;cinb;putout1();for(p=head;p-next!=NULL;)if(p-next-score.english=a&p-next-score.englishnext;if(c=0)cout对不起,没有查找到符合条件的节点!endl;else cout共有c条符合条件的节点.;void checkcomputer(stu *head,stu *end)int a,b,c=0;struct stu *p;couta;cinb;putout1();for(p=head;p-next!=NULL;)if(puter=a&puternext;if(c=0)cout对不起,没有查找到符合条件的节点!endl;else cout共有c条符合条件的节点.;void check(stu *head,stu *end)int a;cout1.查看高数成绩分数段内学生信息endl;cout2.查看英语成绩分数段内学生信息endl;cout3.查看计算机成绩分数段内学生信息endla;switch(a)case 1:checkmath(head,end);break;case 2:checkenglish(head,end);break;case 3:checkcomputer(head,end);void close(stu *head,stu *end)struct stu *p;if(f=fopen(s
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年金融机构与个人投资者P2P借贷业务合作协议书
- 2025年新型医疗仪器区域代理及市场拓展合作协议
- 2025年度高品质智能家居系统装修材料集中采购专项合同
- 2025年新型医疗产品市场推广与精准广告投放合作协议
- 2025年现代简约风格别墅装修设计施工综合服务合同
- 2025年度终止二手房买卖合同及物业维修基金清算与维护责任协议
- 2025年度低碳环保型商用空调采购及运营管理合同
- 2025年度网络文学作品版权侵权赔偿与免责协议书
- 2025年建筑行业起重机租赁及操作人员资格认证及维护保养合同
- 2025年度中学班主任职责履行及教学成果评估合同
- 锂离子电池正极材料研究进展
- 二手房屋买卖物品交接清单
- 技师论文 变频器的维修与保养
- 非标自动化设备项目进度表
- 诊断学教学胸部查体
- 桥梁安全事故案例警示
- YY/T 1095-2015肌电生物反馈仪
- SB/T 10460-2008商用电开水器
- GB/T 9124.1-2019钢制管法兰第1部分:PN系列
- GA 1800.2-2021电力系统治安反恐防范要求第2部分:火力发电企业
- 欣旺集团种禽养殖管理制度手册
评论
0/150
提交评论