`
- 浏览:
145665 次
- 性别:
- 来自:
杭州
-
#include<iostream>
usingnamespacestd;
constintROOM_NUM=4;
constintSTU_NUM_EACH_ROOM=4;
enumOP...{RESIDEIN=1,OUT,QUERY,QUIT};
enumQUER...{BYNO=1,BYNAME,BYROOMNO,ALL,BACK};//查询方式
typedefstructRoom...{
introomNo;
intsNum;//该房间现住人数
intsNo[STU_NUM_EACH_ROOM];//房间里住的学生的学号
structRoom*next;
}Room,*PRoom;
typedefstructStudent...{
intsNo;
charsName[20];
introomNo;
structStudent*next;
}Student,*PStudent;
voidprintMessage(constchar*mess)
...{
cout<<mess;
}
voidmakeRooms(PRoom&prs)
...{
prs=newRoom[ROOM_NUM];
if(prs)
...{
for(inti=0;i<ROOM_NUM;++i)
...{
prs[i].roomNo=i+1;
prs[i].sNum=0;
memset(prs[i].sNo,0,sizeof(prs[i].sNo));
prs[i].next=NULL;
}
}
else
...{
printMessage("宿舍没盖成功,可能是资金的问题! ");
exit(1);
}
}
intgetRoomNo(PRoom&prs)
...{
for(inti=0;i<ROOM_NUM;++i)
...{
if(prs[i].sNum<STU_NUM_EACH_ROOM)
returnprs[i].roomNo;
}
return0;
}
PStudentcheckSno(PStudent&pslh,intsno)
...{
for(PStudentps=pslh->next;ps;ps=ps->next)
...{
if(ps->sNo==sno)
returnps;
}
returnNULL;
}
voidresideIn(PStudent&pslh,PRoom&prs)
...{
cin.clear();
introomNo=getRoomNo(prs);
if(roomNo!=0)
...{
Student*psNew=newStudent;
printMessage("输入学号,姓名:");
if(cin>>psNew->sNo>>psNew->sName)
...{
if(!checkSno(pslh,psNew->sNo))
...{
psNew->roomNo=roomNo;
psNew->next=NULL;
PStudentpst=pslh;
while(pst->next)
pst=pst->next;
pst->next=psNew;
for(inti=0;i<STU_NUM_EACH_ROOM;++i)
if(prs[roomNo-1].sNo[i]==0)
...{
prs[roomNo-1].sNo[i]=psNew->sNo;
break;
}
prs[roomNo-1].sNum++;
pslh->sNo++;//保存总人数
cout<<"入住手续办完,旅途愉快,您的房间是:"<<roomNo<<endl;
}
else
...{
printMessage("该生学号不正确! ");
deletepsNew;
}
}
else
...{
cin.clear();
deletepsNew;
}
}
else
...{
printMessage("对不起,客满 ");
}
}
voidresideOut(PStudent&pslh,PRoom&prs)
...{
printMessage("输入退房者学号:");
intsno;
cin>>sno;
PStudentpst=checkSno(pslh,sno);
if(pst)
...{
PStudentps=pslh;
while(ps->next!=pst)
ps=ps->next;
ps->next=pst->next;
introomNo=pst->roomNo;
for(inti=0;i<STU_NUM_EACH_ROOM;++i)
if(prs[roomNo-1].sNo[i]==pst->sNo)
...{
prs[roomNo-1].sNo[i]=0;
break;
}
prs[roomNo-1].sNum--;
pslh->sNo--;
deletepst;
printMessage("退房成功! ");
}
else
...{
printMessage("该生不存在! ");
}
}
voidqueryByNo(PStudent&pslh,PRoom&prs)
...{
printMessage("输入学号:");
intsno;
cin>>sno;
PStudentpst=checkSno(pslh,sno);
cout<<"查询结果:"<<endl;
if(pst)
...{
cout<<"学号:"<<sno<<endl;
cout<<"姓名:"<<pst->sName<<endl;
cout<<"房间:"<<pst->roomNo<<endl;
cout<<"==============="<<endl;
}
else
...{
printMessage("该生不存在! ");
}
}
voidqueryByName(PStudent&pslh,PRoom&prs)
...{
printMessage("输入姓名:");
charsname[20];
cin>>sname;
boolfound=false;
cout<<"查询结果:"<<endl;
for(PStudentps=pslh->next;ps;ps=ps->next)
...{
if(strcmp(ps->sName,sname)==0)
...{
cout<<"学号:"<<ps->sNo<<endl;
cout<<"姓名:"<<ps->sName<<endl;
cout<<"房间:"<<ps->roomNo<<endl;
cout<<"==============="<<endl;
found=true;
}
}
if(!found)
printMessage("该生不存在! ");
}
voidqueryByRoomNo(PStudent&pslh,PRoom&prs)
...{
printMessage("输入房间号:");
introomNo;
cin>>roomNo;
cout<<"查询结果:"<<endl;
if(roomNo>=ROOM_NUM)
...{
printMessage("无此房间! ");
}
else
...{
cout<<"房间号:"<<roomNo<<endl;
cout<<"学生数:"<<prs[roomNo-1].sNum<<endl;
for(inti=0;i<STU_NUM_EACH_ROOM;++i)
if(prs[roomNo-1].sNo[i]!=0)
...{
cout<<"学号:"<<prs[roomNo-1].sNo[i]<<endl;
}
}
}
voidqueryAll(PStudent&pslh,PRoom&prs)
...{
boolfound=false;
cout<<"查询结果:"<<endl;
for(PStudentps=pslh->next;ps;ps=ps->next)
...{
cout<<"学号:"<<ps->sNo<<endl;
cout<<"姓名:"<<ps->sName<<endl;
cout<<"房间:"<<ps->roomNo<<endl;
cout<<"==============="<<endl;
found=true;
}
if(!found)
printMessage("无记录 ");
}
voidquery(PStudent&pslh,PRoom&prs)
...{
intqueryBy;
printMessage("选择查询方式:");
cin.clear();
while(cin>>queryBy)
...{
if(queryBy==BACK)
break;
switch(queryBy)
...{
caseBYNO:
queryByNo(pslh,prs);
break;
caseBYNAME:
queryByName(pslh,prs);
break;
caseBYROOMNO:
queryByRoomNo(pslh,prs);
break;
caseALL:
queryAll(pslh,prs);
break;
default:
printMessage("选择方式错误,请重新选择! ");
break;
}
printMessage("选择查询方式:");
}
cin.clear();
}
intmain()
...{
PRoompRooms=NULL;
makeRooms(pRooms);
PStudentpStuLinkHeader=newStudent;
pStuLinkHeader->sNo=0;
pStuLinkHeader->next=NULL;
intop;
printMessage("1.入住 ");
printMessage("2.退房 ");
printMessage("3.查询 ");
printMessage("4.退出程序 ");
printMessage("选择服务:");
while(cin>>op)
...{
if(op==QUIT)
break;
switch(op)
...{
caseRESIDEIN:
resideIn(pStuLinkHeader,pRooms);
break;
caseOUT:
resideOut(pStuLinkHeader,pRooms);
break;
caseQUERY:
printMessage("1.按学号 ");
printMessage("2.按名字 ");
printMessage("3.按房间号 ");
printMessage("4.列出所有 ");
printMessage("5.返回上层 ");
query(pStuLinkHeader,pRooms);
break;
default:
printMessage("选择错误,请重新选择! ");
break;
}
printMessage("选择服务:");
cin.clear();
}
return0;
}
分享到:
Global site tag (gtag.js) - Google Analytics
相关推荐
学生成绩管理系统C/C++实现学生成绩管理系统源码.zip 95分以上高分课程设计,下载即用,无需修改。 学生成绩管理系统C/C++实现学生成绩管理系统源码.zip 95分以上高分课程设计,下载即用,无需修改。学生成绩管理...
C/C++语言程序设计 学生公寓管理系统 学生信息包括:学号,姓名,年龄,性别,出生年月,地址,电话,E—mail等。试设计一学生信息管理系统,使之能提供以下功能: 系统以菜单方式工作 学生信息录入功能(学生信息用...
c++ 编程实例 很详细的代码资源 欢迎下载
C语言/C++集成开发环境 Dev-C++。一款优秀的C/C++集成开发软件。
Dev-cpp5.4.0及API帮助文档 2018年蓝桥杯C语言/c++ 需要的同学可以下载使用
基于C/C++模拟处理机调度、存储管理(动态分区分配、分页存储地址转换)和文件系统 基于C/C++模拟处理机调度、存储管理(动态分区分配、分页存储地址转换)和文件系统 基于C/C++模拟处理机调度、存储管理...
C语言/C++ 烟花表白代码 C语言/C++ 烟花表白代码 C语言/C++ 烟花表白代码 C语言/C++ 烟花表白代码
用C/C++编写的一个课堂学生管理系统,跟随老师喊交的作业编写的,所以格式估计会有混杂的情况,紧紧提供给大家参考!
以下是关于“学生信息管理系统”C语言源代码,挺经典的,已经在VC++6.0上成功运行。但愿对你有用!!!
C/C++ 学生信息管理系统 链表 C/C++ 学生信息管理系统 链表
简单的学生管理系统,利用C/C++编写。拥有增、删、改、查、打印、搜索以及排序功能。 推荐使用VS2015或以上版本(支持C11或以上)的编译器运行代码。
已调试通过 如有问题请通过csdn私信联系 MFC学生管理系统 MFC课程的大作业,觉得有用的伙伴可以下载一下 C/C++ 数据结构 QT 管理系统 课程设计
C/C++ 学生成绩 管理系统 代码
C++基于数据库Mysql学生信息管理系统.zip C++基于数据库Mysql学生信息管理系统.zip C++基于数据库Mysql学生信息管理系统.zip C++基于数据库Mysql学生信息管理系统.zip C++基于数据库Mysql学生信息管理系统.zip ...
本资源为大一小项目,C/C++,控制台系统,由于时间紧急,管理员功能的删除和修改未来得及写。
C语言/C++基础之爱心源码,适合初学C语言/C++的小伙伴学习研究,博客中有对应的讲解和演示,避免走弯路,费时费力。也真心希望能够帮助正在苦学C语言/C++ 程序设计的小伙伴们,你们的成长是我最大的幸福
原名《Turbo C/C++ for Windows 集成实验与学习环境》,现已更名为《C/C++程序设计学习与实验系统》,现在已全面支持最新操作系统VISTA,它由从事一线教学的大学教师根据C/C++初学者的特点,量身定制的一个简单易用的...
学生公寓管理系统
C/C++学生信息管理系统、基于OpenCV的车牌识别程序和数据结构相关 该仓库存储的是本人在学习C/C++时候的一些小作品 该仓库存储的是本人在学习C/C++时候的一些小作品,喜欢的朋友欢迎拷贝代码去学习,其中包括: C...