




已阅读5页,还剩3页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
/学生信息管理系统#include#include#include#define NULL 0#define LEN sizeof(struct student)/建立动态链表.cppusing namespace std;struct student int num; char name20; char sex5; float math; float english; int order; struct student *next;int n;int male=0;int famale=0;struct student *creat(void)struct student *head,*p1,*p2;n=0;p1=p2=(struct student *)malloc(LEN);cout下面开始创建链表:endl;cout学号 姓名 性别 数学 英语 p1-nump1-namep1-sexp1-mathp1-english;head=NULL;while(p1-num!=0) if(strcmp(p1-sex,男)=0) male+; else famale+;n+;if(n=1)head=p1;else p2-next=p1;p2=p1;p1=(struct student*)malloc(LEN); cinp1-nump1-namep1-sexp1-mathp1-english;p2-next=NULL;if(head=NULL)cout创建失败,请重建:endl;head=creat();return head;/输出链表的函数void print(struct student *head)cout此时链表的内容为:endl;cout学号 姓名 性别 数学 英语 总分endl;struct student *p;p=head;if(head!=NULL)docout setiosflags(ios_base:left)setw(3)numsetw(6)namesetw(5)sexsetw(5)mathsetw(4)englishsetw(5)math+p-englishresetiosflags(ios_base:left)next;while(p!=NULL);/链表结点的删除操作struct student *del(struct student *head) if(n=0)cout无链表可删除endl;exit(0); int num;coutnum;while(num!=0)struct student *p1,*p2; p1=head; while(num!=p1-num&p1-next!=NULL) p2=p1; p1=p1-next; if(num=p1-num) if(p1=head) if(strcmp(p1-sex,男)=0) male-; else famale-; head=p1-next; else if(strcmp(p1-sex,男)=0) male-; else famale-; p2-next=p1-next; coutnum号已被删除endl; n-; else cout未找到此数据!endl; coutnum;if(n=0)cout此时链表已为空!endl;exit(0);return head;/插入结点struct student *insert(struct student *head)struct student *stu;stu=(struct student*)malloc(LEN);cout学号 姓名 性别 数学 英语 stu-numstu-namestu-sexstu-mathstu-english;while(stu-num!=0) if(strcmp(stu-sex,男)=0) male+; else famale+; n+; struct student *p0,*p1,*p2; p1=head; p0=stu; if(head=NULL) head=p0;p0-next=NULL; else while(p0-nump1-num&p1-next!=NULL)p2=p1;p1=p1-next;if(p0-numnum)if(head=p1)head=p0;else p2-next=p0;p0-next=p1;else p1-next=p0;p0-next=NULL; stu=(struct student*)malloc(LEN);cinstu-numstu-namestu-sexstu-mathstu-english;return head;/根据学号查找void SearchNum(struct student *head)int num;struct student *p;p=head;coutnum;while(p-num!=num&p-next!=NULL)p=p-next;if(p-num=num)cout该生的信息为:endl;cout名次 学号 姓名 性别 数学 英语 总分endl; cout setiosflags(ios_base:left)setw(4)ordersetw(4)numsetw(6)namesetw(5)sexsetw(5)mathsetw(4)englishsetw(5)math+p-englishresetiosflags(ios_base:left)endlendlendl;else cout无该生!endlendlendl;/根据姓名查找void SearchName(struct student *head)struct student *p;p=head;char name20;coutname;while(strcmp(p-name,name)!=0&p-next!=NULL)p=p-next;if(strcmp(p-name,name)=0)cout该生的信息为:endl; cout名次 学号 姓名 性别 数学 英语 总分endl; cout setiosflags(ios_base:left)setw(4)ordersetw(4)numsetw(6)namesetw(5)sexsetw(5)mathsetw(4)englishsetw(5)math+p-englishresetiosflags(ios_base:left)endlendlendl;else cout无该生!endlendlnext;max=(p2-math+p2-english);while(p0-next!=NULL) while(p1!=NULL) if(p1-math+p1-english)max) max=(p1-math+p1-english); p2=p1; p1=p1-next; ; p2-order=+NO; max=p2-order; p2-order=p0-order; p0-order=max; max=p2-num; p2-num=p0-num; p0-num=max; max=p2-math; p2-math=p0-math; p0-math=max; max=p2-english; p2-english=p0-english; p0-english=max; strcpy(temp,p2-name); strcpy(p2-name,p0-name); strcpy(p0-name,temp); strcpy(temp,p2-sex); strcpy(p2-sex,p0-sex); strcpy(p0-sex,temp); p0=p0-next; p2=p0; p1=p2-next; max=(p2-math+p2-english);if(p0-next=NULL)p2-order=+NO;coutorder*endl;return head;/链表的输出void print2(struct student *head)cout此时链表的内容为:endl;cout名次 学号 姓名 性别 数学 英语 总分endl;struct student *p;p=head;int No=1;if(head!=NULL)docout setiosflags(ios_base:left)setw(4)Nosetw(4)numsetw(6)namesetw(5)sexsetw(5)mathsetw(4)englishsetw(5)math+p-englishresetiosflags(ios_base:left)next;No+;while(p!=NULL);coutendlendlendl;/主函数int main() struct student *head; int a;coutendlendlendlttt 欢迎使用学生信息管理系统endlendlendl; coutttt1、创建链表并按总成绩排序endl; coutttt2、根据学号来查询学生信息endl;coutttt3、根据姓名来查询学生信息endl; coutttt4、删除学生、删后自动排序endl; coutttt5、添加学生、添后自动排序endl; coutttt6、计算总人数及男女生人数endl; coutttt0、结束程序endlendlendlendlendl;while(a)couta;if(a=0)cout已经退出程序!6)cout无该选项,请从0-6中选择endlendlendl; switch(a)case 1:head=creat();head=sort(head);print2(head);break;case 2:SearchNum(head);break;c
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年福建省泉州市永春县永源城市建设有限公司招聘11人考前自测高频考点模拟试题及一套答案详解
- 2025年9月27日湖南省供销合作总社遴选业务水平测试面试真题及答案解析
- 2025年降台铣床项目发展计划
- 2025年脑病医院项目建议书
- 小学安全专项培训内容课件
- 2025广东中山市港口镇水务事务中心招聘勤杂工6人考前自测高频考点模拟试题及一套参考答案详解
- HO-PEG-NH-Fmoc-MW-3400-生命科学试剂-MCE
- H1L1A1B3-生命科学试剂-MCE
- Glycidyl-behenate-d5-生命科学试剂-MCE
- 生物产业市场预测与投资机会研究
- 苏教版三年级数学(下册)《间隔排列》课件
- 2023-2023年中国工商银行校园招聘考试历年真题、考查知识点以及备考指导
- 临时聘用合同模板(三篇)
- 《复旦大学介绍》
- 电力系统分析基础教案-按课时
- 动漫及动漫文化的定义
- 江苏亿洲再生资源科技有限公司资源综合利用技改提升项目 环评报告书
- 质量改进培训-课件
- 马云演讲中英文版
- 2022自考英语二课文中英文对照
- 弱电桥架安装及电缆敷设施工方案(PPT)
评论
0/150
提交评论