C++课程设计酒店客房预订系统.docx
《C++课程设计酒店客房预订系统.docx》由会员分享,可在线阅读,更多相关《C++课程设计酒店客房预订系统.docx(11页珍藏版)》请在冰点文库上搜索。
C++课程设计酒店客房预订系统
面向对象程序课程设计
(2013/2014学年第一学期第17周)
指导教师:
庄巧莉、肖荣
班级:
学号:
姓名:
目录
一、题目
二、系统结构图
三、类的设计
四、程序代码与说明
五、运行结果与分析
六、心得与体会
1、
【题目】酒店客房预订系统
【目的】
通过设计一个小型的快捷式酒店客房预订系统,训练综合运用所学知识处理实际问题的能力,强化面向对象的程序设计理念,使自己的程序设计与调试水平有一个明显的提高。
【要求】
1、每个学生必须独立完成;
2、课程设计时间为1周;
3、设计语言采用C++;
4、学生有事离校必须请假。
课程设计期间,无故缺席按旷课处理;缺席时间达四分之一以上者,未按规定上交实验报告的学生,其成绩按不及格处理。
【内容简介】
有一个小型的快捷式商务酒店,该酒店共有10个房间,每个房间有两张床位,酒店全天24小时接受来客的客房预订服务。
该酒店现计划使用客房预订系统来为顾客提供更方便快捷的客房预订服务。
现在请你编写一个酒店客房预订系统的程序,使得这个客房预订系统能够正确工作。
【考核标准】
1、能够正确接受顾客的预订客房和退房申请,成绩≥60;
2、能够统计每一天客房的预订情况,成绩≥70;
3、能够实现每天客房预订信息到文件的导出和导入,成绩≥80;
4、能够考虑不同类型(标准间、大床房、套房)的客房和价格,界面设计友好,成绩≥90。
请仔细考虑这个题目中出现的各个实体,考虑如何保存数据。
2、系统结构图
用户选择退房/订房->选择房间种类->将选择传递到类改变类相对应的的私有成员值
三、类的设计
类hotel
voidchoose(inta,intb);记录用户的选择,a记录退房订房选择,b记录房间种类的选择
voidbook(intb);订房
intgetstandard();输出标准间当前余量
intgetqueen();输出大床房当前余量
intgetdeluxe();输出豪华房当前余量
voidquit(intb);退房
voiddisplay();输出房间统计报表
intstandard,queen,deluxe,x;分别为标准间,大床房,豪华房余量,和用户选择退房或订房
intgetempty(inti);
voidchangeempty(inti);
四、程序代码与说明
#include
#include
#include
#include
#include
#defineN20
usingnamespacestd;
structnode
{
intnum;
intempty;
};
classhotel{
private:
intstandard;
intqueen;
intdeluxe;
intx;
nodero[N];
public:
hotel(){}
hotel(inta,intb,intc){
standard=a;queen=b;deluxe=c;
inti,j;
for(i=1,j=0;i<=10;i++,j++){
room.ro[j].num=i;
room.ro[j].empty=0;}}
voidchoose(inta,intb);
voidbook(intb);
intgetstandard(){returnstandard;}
intgetqueen(){returnqueen;}
intgetdeluxe(){returndeluxe;}
intgetempty(inti);
voidchangeempty(inti);
voidquit(intb);
voiddisplay(){
cout<<"-------------------------------------------\n";
cout<<"房间类型:
\t\t"<<"余量\t\t"<<"价格\t"<<"已预订\n";
cout<<"标准间(总5间):
\t"<cout<<"大床房(总3间):
\t"<cout<<"豪华房(总2间):
\t"<cout<<"-------------------------------------------\n";
}
}room;
voidhotel:
:
changeempty(inti){
if(room.ro[i-1].empty==0)
room.ro[i-1].empty=1;
}
inthotel:
:
getempty(inti){
if(room.ro[i].empty==1)
return1;
elseif(room.ro[i].empty==0)
return0;
}
voidhotel:
:
choose(inta,intb)
{
x=a;
if(x==1)
book(b);
if(x==2)
quit(b);
}
voidhotel:
:
book(intb){
intm;
if(b==1){
if(standard==0)
cout<<"该房间已订满,请重新选择!
\n";
else{
cout<<"请选择房间号:
1.1012.1023.1034.1045.105\n";
cin>>m;
if(room.ro[m-1].empty==0){
room.ro[m-1].empty=1;standard--;
cout<<"订房成功!
\n";}
elseif(room.ro[m-1].empty==1){
cout<<"该房间已有人,请重新选择房间\n";
}
}
}
if(b==2){
if(queen==0)
cout<<"该房间已订满,请重新选择!
\n";
else{
cout<<"请选择房间号:
6.1067.1078.108\n";
cin>>m;
if(room.ro[m-1].empty==0){
room.ro[m-1].empty=1;queen--;
cout<<"订房成功!
\n";}
elseif(room.ro[m-1].empty==1){
cout<<"该房间已有人,请重新选择房间\n";
}
}
}
if(b==3){
if(deluxe==0)
cout<<"该房间已订满,请重新选择!
\n";
else{
cout<<"请选择房间号:
9.10910.110\n";
cin>>m;
if(room.ro[m-1].empty==0){
room.ro[m-1].empty=1;deluxe--;
cout<<"订房成功!
\n";}
elseif(room.ro[m-1].empty==1){
cout<<"该房间已有人,请重新选择房间\n";
}
}
}
}
voidhotel:
:
quit(intb){
intn;
cout<<"请输入你要退订的房间号:
1.1012.1023.1034.1045.1056.1067.1078.1089.10910.110\n";
cin>>n;
if(room.ro[n-1].empty==1){
room.ro[n-1].empty=0;
if(n>=1&&n<=5)standard++;
if(n>5&&n<9)queen++;
if(n>=9&&n<=10)deluxe++;
cout<<"退房成功!
\n";}
elseif(room.ro[n-1].empty==0)
cout<<"该房间未被预订,无法退订!
";
}
voidmain(){
inti,j,k;
ints,q,d;
charword[10];
s=5;q=3;d=2;k=1;
ifstreamfin;
fin.open("a.txt");
fin>>word>>s>>word>>q>>word>>d;
hotelh(s,q,d);
while(fin>>j)
h.changeempty(j);
fin.close();
while(k){
cout<<"-------------------------------------\n";
cout<<"您好!
欢迎光临!
\n";
cout<<"请输入您要进行的操作:
\n";
cout<<"1.订房\t"<<"2.退房\n";
cin>>i;
cout<<"请输入您要进行操作的房间类型:
\n";
cout<<"1.标准间\t"<<"2.大床房\t"<<"3.豪华房\n";
cin>>j;
h.choose(i,j);
h.display();
cout<<"按0键退出程序并保存,按其他继续\n";
cin>>k;
}
s=h.getstandard();
q=h.getqueen();
d=h.getdeluxe();
ofstreamfout;
fout.open("a.txt",ios:
:
out);
fout<<"standard"<<""<
for(i=0;i<10;i++){
j=h.getempty(i);
if(j==1)
fout<
}
fout.close();
}
5、运行结果与分析
六、心得与体会
通过本次实验,我可以很好的掌握类的应用,通过一个简单的类实现了该程序,并没有用到复杂的继承和虚基类,同时,定义的记录数据也很简单,没有用到数组结构,不足也就是不能记录用户的信息,不能把每个房间和用户对应起来,但是可以实现单纯的订房退房和房间信息变化的记录。
最后,可以将每次结束时的信息保存在对应文件中,并在每次打开时读取上次的信息。
考核成绩评定表
平时成绩
答辩成绩
总成绩