




免费预览已结束,剩余24页可下载查看
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
河南工业大学 计科0906 马飞扬根据本报告,可完全实现建立运行宿舍管理系统,这是我c+的课程设计。1:工程结构初始信息:2:源代码main.cpp:#include/预编译语句#include/#include/#include/using namespace std;/#includeshow.h/文件包含语句#includeshow2.h/#includedenglu.h/#includejianlixinxi.h/#includechaxun.h/#includexiugai.h/#includeshanchu.h/#includehuizong.h/#includexiumima.h/#includezhuce.h/#includeweisheng.h/void main()int choice=0;/记录选择denglu();/输入登录信息show();/显示菜单cinchoice;while(choice!=0)/循环输入选择 switch(choice) case 1:jianli();break;/建立宿舍信息 case 2:chaxun();break;/查询学生信息 case 3:huizong();break;/宿舍信息汇总 case 4:xiugai();break;/修改学生信息 case 5:zhuce();break;/添加学生信息 case 6:shanchu();break;/删除学生信息 case 7:weisheng();break;/宿舍卫生评比 case 8:xiumima();break;/修改登录信息 case 0:break; default:cout您按错了!choice;chaxun.h:void chaxue(int renshu);/按学号查询void chaban(int renshu);/按班级查询void chasu(int renshu);/按宿舍查询struct student2/定义存储信息的结点结构char name20;char number20;char banji20;int sushehao;student2 array1100;/定义存储信息的线性结构数组void chaxun()student2 p;/辅助结点变量int choice=0;int renshu=0; ifstream fin2(学生信息.txt);if(!fin2)couterror!p.numberp.banjip.sushehao;renshu+;renshu-;fin2.close();cout1:按学号查询;coutttt 2:按班级查询n;cout3:按宿舍查询n;coutchoice;while(choice!=0)/循环操作 switch(choice) case 1:chaxue(renshu);break; case 2:chaban(renshu);break; case 3:chasu(renshu);break; case 0:break; default:cout您输错了!endl;break; coutchoice;cout已退出!endl;show2();/显示主菜单void chaxue(int renshu)student2 p;int i=0;char xuehao20;coutxuehao;/输入查询的学号ifstream fin1(学生信息.txt);if(!fin1)couterror!endl;exit(0);for(int j=0;p.numberp.banjip.sushehao;if(!strcmp(p.number,xuehao)/找到相关信息后进行输出cout姓名:tt 学号:p.numberendl;cout班级:p.banjitt 宿舍号:p.sushehaoendl;i+;break;fin1.close();if(i=0)cout没有该生信息!endl;void chaban(int renshu)/实现细节类似上个函数student2 p;int i=0;char banji20;coutbanji;ifstream fin1(学生信息.txt);if(!fin1)couterror!endl;exit(0);for(int j=0;p.numberp.banjip.sushehao;if(!strcmp(p.banji,banji)cout姓名:tt 学号:p.numberendl;cout班级:p.banjitt 宿舍号:p.sushehaoendl;i+;fin1.close();if(i=0)cout没有该班学生信息!endl;void chasu(int renshu)/实现细节类似上个函数student2 p;int i=0;int sushehao;coutsushehao;ifstream fin1(学生信息.txt);if(!fin1)couterror!endl;exit(0);for(int j=0;p.numberp.banjip.sushehao;if(p.sushehao=sushehao)cout姓名:tt 学号:p.numberendl;cout班级:p.banjitt 宿舍号:p.sushehaoendl;i+;fin1.close();if(i=0)cout该宿舍无人入住!endl;denglu.h:void denglu()char yonghu120;/存储用户输入的登录信息char mima110;/char yonghu220;/存储当前系统设定的登录信息char mima210;/coutyonghu1;coutmima1;ifstream fin1(登录信息.txt);if(!fin1)couterror!yonghu2 mima2;fin1.close();if(strcmp(yonghu1,yonghu2)|strcmp(mima1,mima2)/判断是否为合法用户cout用户名或密码错误!endl;exit(0);huizong.h:void huizong()char louhao20;int loucheng=0;int fangjian=0;int rongliang=0;int i=0;/记录宿舍楼的基本信息student2 array4100;/存储宿舍楼的所有学生信息int susheshu=0;int renshu=0;/记录宿舍楼已入住的宿舍数及总入住人数ifstream fin(学生信息.txt);if(!fin)couterror!array4renshu.numberarray4renshu.banjiarray4renshu.sushehao;renshu+;renshu-;/记录入住人数fin.close();if(renshu!=0) susheshu+;/ for(i=1;irenshu;i+)/计算已入住的宿舍个数 if(array4i.sushehao!=array4i-1.sushehao) susheshu+; ifstream fin1(宿舍信息.txt);if(!fin1)couterror!louhao;/宿舍楼编号fin1loucheng;/楼层个数fin1fangjian;/每层房间数fin1rongliang;/房间容量fin1.close();coutlouhao宿舍楼信息汇总:endl;cout已入住:renshu名学生;/输出已入住的人数couttt 剩余容纳量:loucheng*fangjian*rongliang-renshuendl;/剩余容纳量cout空房间数:loucheng*fangjian-susheshuendl;/空房间数show2();/显示主菜单jianlixinxi.h:struct student/存储学生信息的单链表结点存储结构char name20;char number20;char banji20;int sushehao;student*next;struct sushe/存储各房间信息的单链表头结点int renshu;student*next;void jianli()int choice;coutchoice;/if(choice)ofstream fout3;fout3.open(学生信息.txt);if(!fout3)couterrorendl;exit(0);fout3.eof();/格式化当前记录的学生信息fout3.close; char louhao20;int loucheng;int fangjian;int rongliang;/存储宿舍楼基本信息 coutlouhao;/coutloucheng;/coutfangjian;/coutrongliang;/ofstream fout1(宿舍信息.txt);if(!fout1)couterror!endl;exit(0);fout1louhaoendl;/输入到文件fout1louchengendl;/fout1fangjianendl;/fout1rongliangendl;/fout1.close();for(int i=0;iloucheng;i+)/按楼层数逐个建立每层信息sushe*lou=new sushefangjian;/定义存储每层信息的线性结构for(int j=0;jfangjian;j+)/对该线性结构进行初始化louj.renshu=0;/louj.next=NULL;/student*p=NULL;/辅助结点变量p=new student;cout第i+1层信息(宿舍号-1进入下一层):endl;cout宿舍号((i+1)*100(i+1)*100+fangjian-1p-sushehao;/输入宿舍号以进行下面的操作while(p-sushehao!=-1)sushe*q=NULL;coutp-name;coutp-number;coutp-banji;if(loup-sushehao%100.renshusushehao%100.renshu=0)/空房间直接插入loup-sushehao%100.next=p;p-next=NULL;loup-sushehao%100.renshu+;else/非空房间先找到链表尾结点再进行插入q=loup-sushehao%100.next;for(int m=0;msushehao%100.renshu-1;m+)q=q-next;q-next=p;p-next=NULL;loup-sushehao%100.renshu+;else/房间已满输入无效cout该宿舍已满,此次输入无效!endl;p=new student;coutp-sushehao;if(p-sushehao=-1)/退出本层信息输入后输入本层信息至文件ofstream fout2;fout2.open(学生信息.txt,ios:app);if(!fout2)couterrorendl;exit(0);for(j=0;jfangjian;j+)if(louj.renshu!=0)p=louj.next;for(int s=0;slouj.renshu;s+)fout2nameendl;fout2numberendl;fout2banjiendl;fout2sushehaonext;fout2.close();deletelou;cout已建立宿舍信息!endl;show2();/显示主菜单shanchu.h:void mingshan();/按名字进行删除void xueshan();/按学号进行删除void shanchu()int choice=0;cout1:按名字删除:;couttt 2:按学号删除:n;coutchoice;while(choice!=0)/循环操作switch(choice)case 1:mingshan();break;case 2:xueshan();break;case 0:break;default:cout您按错了!endl;break;coutchoice;cout已退出!endl;show2();/显示主菜单void mingshan() student2 array3100;/存储当前所有学生信息int renshu=0;char name20;/存储待删除信息的名字int j=0;ifstream fin(学生信息.txt);if(!fin)couterror!array3renshu.numberarray3renshu.banjiarray3renshu.sushehao;renshu+;renshu-;/记录人数fin.close();coutname;/输入待删除名字for(int i=0;irenshu;i+)/循环查找线性表if(!strcmp(,name)/找到相关信息 ofstream fout3; fout3.open(学生信息.txt); if(!fout3) couterrorendl; exit(0); fout3.eof();/格式化当前信息 fout3.close; j+; ofstream fout; fout.open(学生信息.txt,ios:app); if(!fout) couterror!endl; exit(0); for(int s=0;srenshu;s+)/输入非删除信息至文件 if(s!=i) endl; foutarray3s.numberendl; foutarray3s.banjiendl; foutarray3s.sushehaoendl; fout.close(); cout已删除!endl; break;if(j=0)/查找失败时cout不存在该生信息!endl;void xueshan()/实现细节于上个函数 student2 array4100;int renshu=0;char number20;int j=0;ifstream fin(学生信息.txt);if(!fin)couterror!array4renshu.numberarray4renshu.banjiarray4renshu.sushehao;renshu+;renshu-;fin.close();coutnumber;for(int i=0;irenshu;i+)if(!strcmp(array4i.number,number) ofstream fout3; fout3.open(学生信息.txt); if(!fout3) couterrorendl; exit(0); fout3.eof(); fout3.close; j+; ofstream fout; fout.open(学生信息.txt,ios:app); if(!fout) couterror!endl; exit(0); for(int s=0;srenshu;s+) if(s!=i) endl; foutarray4s.numberendl; foutarray4s.banjiendl; foutarray4s.sushehaoendl; fout.close(); cout已删除!endl; break;if(j=0)cout不存在该生信息!endl;show.h:void show()/主界面显示信息time_t t;time(&t); cout -宿舍管理查询系统-endl; cout ttt 时间: ctime(&t); cout-n; cout1:建立宿舍信息; coutttttttt 2:查询学生信息n; cout3:宿舍信息汇总; coutttttttt 4:修改学生信息n; cout5:注册学生信息; coutttttttt 6:删除学生信息n; cout7:宿舍卫生评比; coutttttttt 8:修改登录信息n; cout-n; cout请选择(0退出):;show2.h:void show2()/进行操作后显示的主界面信息 cout-n; cout1:建立宿舍信息; coutttttttt 2:查询学生信息n; cout3:宿舍信息汇总; coutttttttt 4:修改学生信息n; cout5:注册学生信息; coutttttttt 6:删除学生信息n; cout7:宿舍卫生评比; coutttttttt 8:修改登录信息n; cout-n; cout请选择(0退出):;weisheng.h:struct wei/宿舍卫生存储结构int sushehao;int score;void sort(wei*l,int low,int high);/快速排序函数int partion(wei*l,int low,int high);/返回枢轴位置void weisheng()student2 array5100;/学生信息存储结构wei sheng100;/宿舍卫生信息存储结构int renshu=0;int susheshu=0;int i=0;ifstream fin1(学生信息.txt);if(!fin1)couterror!array5renshu.numberarray5renshu.banjiarray5renshu.sushehao;renshu+;renshu-;/记录人数fin1.close();if(renshu!=0)shengsusheshu.sushehao=array5i.sushehao;susheshu+;for(i=1;irenshu;i+)/建立已入住的宿舍信息存储数组if(array5i-1.sushehao!=array5i.sushehao)shengsusheshu.sushehao=array5i.sushehao;susheshu+;cout为各宿舍打分(0100):endl;/为各入住宿舍打分for(i=0;isusheshu;i+)cout宿舍shengi.sushehaoshengi.score;wei*l;l=sheng;i=susheshu-1;sort(l,0,i);/按得分对宿舍信息进行排序ofstream fout3;fout3.open(宿舍卫生信息.txt);if(!fout3)couterror!endl;exit(0); fout3.eof();/格式化上次得分信息fout3.close();ofstream fout2;fout2.open(宿舍卫生信息.txt,ios:app);if(!fout2)couterror!endl;exit(0);for(i=0;isusheshu;i+)/写入宿舍卫生信息至文件fout2shengi.sushehaoendl;fout2shengi.scoreendl;fout2.close();int susheshu2=susheshu;cout得分最高的宿舍为:=2&shengsusheshu2-2.score=shengsusheshu2-1.score)/循环输出最高得分宿舍cout,;coutshengsusheshu2-2.sushehao;susheshu2-;coutendl;i=0;if(shengi.score60)cout不及格宿舍有:shengi.sushehao;i+;while(isusheshu&shengi.score60)/循环输出不及格宿舍信息cout,; coutshengi.sushehao;i+;coutendl;elsecout所有宿舍均及格!endl;elsecout当前宿舍信息为空!endl;cout各宿舍得分已输入文件!endl;show2();/显示主菜单void sort(wei*l,int low,int high)/快速排序函数if(lowhigh)int key=partion(l,low,high);sort(l,low,key-1); sort(l,key+1,high);int partion(wei*l,int low,int high)/返回枢轴位置int p=0;int q=0;int key=llow.score;while(lowhigh)while(low=key)-high;p=llow.score;q=llow.sushehao;llow.score=lhigh.score;llow.sushehao=lhigh.sushehao;lhigh.score=p;lhigh.sushehao=q;while(lowhigh&llow.score=key)+low;p=llow.score;q=llow.sushehao;llow.score=lhigh.score;llow.sushehao=lhigh.sushehao;lhigh.score=p;lhigh.sushehao=q;return low;xiugai.h:void mingxiu(int renshu);/按名字修改void xuexiu(int renshu);/按学号修改student2 array2100;/存储学生信息void xiugai()int choice=0;int renshu=0;ifstream fin(学生信息.txt);if(!fin)couterror!array2renshu.numberarray2renshu.banjiarray2renshu.sushehao;renshu+;renshu-;fin.close();cout1:按名字修改:;couttt 2:按学号修改:n;coutchoice;while(choice!=0)switch(choice)case 1:mingxiu(renshu);break;case 2:xuexiu(renshu);break;case 0:break;default:cout您按错了!endl;break;coutchoice;cout已退出!endl;show2();void mingxiu(int renshu)char na20;int j=0;coutna;for(int i=0;irenshu;i+)if(!strcmp(,na)/找到相关信息进行修改 ; coutarray2i.number; coutarray2i.banji; coutarray2i.sushehao; j+; ofstream fout3; fout3.open(学生信息.txt); if(!fout3) couterrorendl; exit(0); fout3.eof(); fout3.close; ofstream fout; fout.open(学生信息.txt,ios:app); if(!fout) couterror!endl; exit(0); for(int s=0;srenshu;s+)/写入修改后的信息至文件 endl; foutarray2s.numberendl; foutarray2s.banjiendl; foutarray2s.sushehaoendl; fout.close(); cout已修改,; break;if(j=0)/查找失败cout不存在该生信息!endl;void xuexiu(int renshu)/实现细节类是与上个函数char number20;int j=0;coutnumber;for(int i=0;irenshu;i+)if(!strcmp(array2i.number,number) ; coutarray2i.number; coutarray2i.banji; coutarray2i.sushehao; j+; ofstream fout3; fout3.open(学生信息.txt); if(!fout3) couterrorendl; exit(0); fout3.eof(); fout3.close; ofstream fout; fout.open(学生信息.txt,ios:app); if(!fout) couterror!endl; exit(0); for(int s=0;srenshu;s+) endl; foutarray2s.numberendl; foutarray2s.banjiendl; foutarray2s.sushehaoendl; fout.close(); cout已修改,; break;if(j=0)cout不存在该生信息!endl;xiumima.h:void xiumima()char yonghu120;/存储登录信息的辅助数组char mima110;/char yonghu20;/char mima10;/ifstream fin1(登录信息.txt);if(!fin1)couterror!yonghu/读入旧的登录信息 mima;/fin1.close();coutyonghu1;coutmima1;if(!(strcmp(yonghu1,yonghu)|strcmp(mima1,mima)/判断是否为合法用户coutyonghu;coutmima;cout已完成修改!endl;ofstream fout(登录信息.txt);if(!fout)couterror!endl;exit(0);foutyonghuendl;/修改登录信息foutmimaendl;/elsecou
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 生物合成途径优化-第2篇-洞察及研究
- 食品添加剂标识趋势-洞察及研究
- 运动心理大数据分析-洞察及研究
- 诉讼成本控制策略-洞察及研究
- 卷烟配送中心不同分拣模式下的成本管控策略与实践
- 卡拉胶寡糖及其衍生物:制备工艺与抗疱疹病毒活性的深度剖析
- 2025贵州毕节黔西市面向社会招聘城市社区工作者33人2025-08-笔试备考题库及答案解析
- 2025广东阳江市阳东区选聘区属国企职工15人笔试备考试题及答案解析
- 2025福建福州市交通建设集团有限公司正式合同制人员招聘4人备考试题及答案解析
- 2025安徽安庆市劳务派遣驾驶员招聘3人备考题库及答案解析
- (高清版)DB11∕T 3046-2025 健康体检质量控制规范
- 【公开课】热量+比热容(教学课件)2025-2026学年初中物理人教版(2024)九年级全一册
- 地产直播活动方案
- 口腔病理学牙发育异常
- 棋牌室员工管理制度
- 2025前期咨询服务合同协议书模板
- 公共空间设计课程标准
- 智能医疗中的知识图谱与多模态数据融合研究-洞察阐释
- 《绿色建筑施工培训课件》资料
- 留疆战士考试试题及答案
- 黄委会面试真题及答案
评论
0/150
提交评论