首页 c++学生管理系统链表

c++学生管理系统链表

举报
开通vip

c++学生管理系统链表#include#include#include#includeusingnamespacestd;structStudent{stringstuId;stringstuName;stringstuMajor;Student*next;};Student*pHead=NULL;//头指针Student*pEnd=NULL;//尾指针voidMeun();//菜单voidAddStuInfo(stringid,stringname,stringmajor);//创建表以及添加数据Student*LookStuInfo...

c++学生管理系统链表
#include#include#include#includeusingnamespacestd;structStudent{stringstuId;stringstuName;stringstuMajor;Student*next;};Student*pHead=NULL;//头指针Student*pEnd=NULL;//尾指针voidMeun();//菜单voidAddStuInfo(stringid,stringname,stringmajor);//创建表以及添加数据Student*LookStuInfo(stringid);//查找数据voidAddStuInfoToHead(stringid,stringname,stringmajor);//表头添加数据voidInsertsStuInfo(Student*stu,stringindex,stringid,stringname,stringmajor);//插入数据voidAlterStuInfo(Student*stu,stringid,stringname,stringmajor);//修改数据voidPrintStuInfo();//打印数据voidDeleteStuInfo(Student*stu,stringid);//删除数据voidWriteFile();//数据写入到文本voidReadFile();//从文本读取数据voidDeleteList();//销毁表intmain(){Meun();Student*p=pHead;stringsid,sname,smajor,id;intiChoose;while(1){cout<<"请选择你的操作(按[9]可查看操作命令):"<>iChoose;switch(iChoose){case1:while(1){cout<<"请输入学号:(输入q退出输入)";cin>>sid;if(sid=="q"){cout<<"已退出数据输入"<>sname;cout<<"请输入专业:";cin>>smajor;AddStuInfo(sid,sname,smajor);}}break;case2:cout<<"请输入查询学号:";cin>>sid;p=LookStuInfo(sid);if(p!=NULL){cout<<"找到以下信息:"<stuId<<"\t姓名:"<stuName<<"\t专业:"<stuMajor<>sid;p=LookStuInfo(sid);if(p==NULL){cout<<"不存在信息"<>sname;cout<<"请输入修改后专业:";cin>>smajor;AlterStuInfo(p,sid,sname,smajor);}break;case4:PrintStuInfo();break;case5:cout<<"请输入删除的学生学号:";cin>>sid;DeleteStuInfo(p,sid);break;case6:cout<<"输入被插入的学号";cin>>id;p=LookStuInfo(sid);if(p==NULL){cout<<"不存在该学号"<>sid;cout<<"请输入姓名:";cin>>sname;cout<<"请输入专业:";cin>>smajor;InsertsStuInfo(p,id,sid,sname,smajor);}break;case7:WriteFile();break;case8:ReadFile();break;case9:Meun();break;case0:exit(0);break;default:cout<<"请输入正确命令"< 管理系统 工资管理系统慧云智能化管理系统免费考勤管理系统员工工资计算excel病人信息管理系统 ***************\n";cout<<"\t********************************************\n";cout<<"\t**[1]添加学生信息**\n";cout<<"\t**[2]查找学生信息**\n";cout<<"\t**[3]修改学生信息**\n";cout<<"\t**[4]显示学生信息**\n";cout<<"\t**[5]删除学生信息**\n";cout<<"\t**[6]插入学生信息**\n";cout<<"\t**[7]保存信息到文件**\n";cout<<"\t**[8]从文件读取信息**\n";cout<<"\t**[0]退出管理系统**\n";cout<<"\t********************************************\n";cout<<"\t********************************************\n";}voidAddStuInfo(stringid,stringname,stringmajor){Student*pNew=newStudent;pNew->stuId=id;pNew->stuName=name;pNew->stuMajor=major;pNew->next=NULL;if(pHead==NULL||pEnd==NULL){pHead=pNew;pEnd=pNew;}else{pEnd->next=pNew;pEnd=pNew;}}Student*LookStuInfo(stringid){Student*p=pHead;if(p==NULL){cout<<"没有数据"<stuId==id){returnp;break;}elseif(p->next==NULL){returnNULL;}p=p->next;}}}voidAddStuInfoToHead(stringid,stringname,stringmajor){Student*pNew=newStudent;pNew->stuId=id;pNew->stuName=name;pNew->stuMajor=major;pNew->next=NULL;if(pHead==NULL||pEnd==NULL){pHead=pEnd=pNew;}else{pNew->next=pHead;//新节点的下一个指向头pHead=pNew;}}voidInsertsStuInfo(Student*stu,stringindex,stringid,stringname,stringmajor){stu=LookStuInfo(index);if(stu==pHead){AddStuInfoToHead(id,name,major);}elseif(stu==pEnd){AddStuInfo(id,name,major);}else{Student*pNew=newStudent;pNew->stuId=id;pNew->stuName=name;pNew->stuMajor=major;pNew->next=NULL;pNew->next=stu->next;stu->next=pNew;}}voidAlterStuInfo(Student*stu,stringid,stringname,stringmajor){stu=LookStuInfo(id);if(stu==NULL)cout<<"没有数据"<stuName=name;stu->stuMajor=major;}}voidPrintStuInfo(){Student*p=pHead;//定义临时节点if(p==NULL)cout<<"该链表为空,无数据"<stuId<<"\t姓名:"<stuName<<"\t专业:"<stuMajor<next;}}voidDeleteStuInfo(Student*stu,stringid){stu=LookStuInfo(id);if(stu!=NULL){if(pHead==stu){pHead=stu->next;}elseif(stu==pEnd){Student*ptemp=pHead;while(ptemp){if(ptemp->next==stu){ptemp->next=NULL;}ptemp=ptemp->next;}}else{Student*ptemp=pHead;while(ptemp){if(ptemp->next==stu){ptemp->next=stu->next;}ptemp=ptemp->next;}}}}voidWriteFile(){if(pHead==NULL){cout<<"链表没有数据"<stuId<<"\t姓名:\t"<stuName<<"\t专业:\t"<stuMajor<<"\n";p=p->next;}outFile.close();cout<<"写入成功"<next;//移到下一个节点deletep;//删除节点p=NULL;}}
本文档为【c++学生管理系统链表】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
下载需要: 免费 已有0 人下载
最新资料
资料动态
专题动态
is_113440
暂无简介~
格式:pdf
大小:236KB
软件:PDF阅读器
页数:10
分类:
上传时间:2020-07-18
浏览量:0