当前位置:编程学习 > C/C++ >>

C++客房管理系统

请把源代码发给我,还要有相关的注释。最好是具体点的。我是新手,想学习下。还有就是设计程序时候一开始的思想。==应该分哪些类==
邮箱是1094015908@qq.com
在此谢谢了
答案:思路上要注意两点:

1.客房的增删改查
2.退房的费用计算
第一点类似于数据库操作,第二点要区分中午12点之前退房还是之后退房,如果是超过12点之后退房的,要额外增加费用。

代码如下:

#include<iostream>
#include<string>
#include<fstream>
#include<cstdlib>
#include<time.h>
using namespace std;
class KF{
public:
string id;
string state;
int level;
string desc;
struct tm local;
}kfs[100];
time_t t;
struct tm locNow;
int main(){
int Sel,SelSub;
int i,cnt=0,cntDay;
string strIn;
while(cout<<"\n\n1.客房列表\n2.增加客房\n3.删除客房\n4.修改客房\n5.查询客房\n6.客房操作\n7.退出\n",cin>>Sel){
switch(Sel){
case 1:
cout<<"\n客房列表:(客房号|客房状态|客房等级|客房描述)\n";
for(i=0;i<cnt;++i)cout<<kfs[i].id<<'|'<<kfs[i].state<<'|'<<kfs[i].level<<'|'<<kfs[i].desc<<endl;
break;
case 2:
cout<<"\n客房号:\n";
cin>>kfs[cnt].id;
cout<<"客房等级:\n";
cin>>kfs[cnt].level;
cout<<"客房描述:\n";
cin>>kfs[cnt].desc;
kfs[cnt].state="空";
cout<<"增加成功!当前客房数量="<<++cnt<<endl;
break;
case 3:
cout<<"\n客房号:\n";
cin>>strIn;
for(i=0;i<cnt;++i)if(kfs[i].id==strIn)break;
if(i<cnt){
for(;i<cnt-1;++i)kfs[i]=kfs[i+1];
--cnt;
cout<<"删除客房号="<<strIn<<"成功!当前客房数量="<<cnt<<endl;
}else cout<<"无此客房号!\n";
break;
case 4:
cout<<"\n客房号:\n";
cin>>strIn;
for(i=0;i<cnt;++i)if(kfs[i].id==strIn)break;
if(i<cnt){
cout<<"请重新输入该客房信息:\n";
cout<<"客房号:\n";
cin>>kfs[i].id;
cout<<"客房等级:\n";
cin>>kfs[i].level;
cout<<"客房描述:\n";
cin>>kfs[i].desc;
cout<<"修改原客房号="<<strIn<<"成功!当前客房数量="<<cnt<<endl;
}else cout<<"无此客房号!\n";
break;
case 5:
cout<<"\n客房号:\n";
cin>>strIn;
for(i=0;i<cnt;++i)if(kfs[i].id==strIn)break;
if(i<cnt){
cout<<"\n查到该客房!:(客房号|客房状态|客房等级|客房描述)\n";
cout<<kfs[i].id<<'|'<<kfs[i].state<<'|'<<kfs[i].level<<'|'<<kfs[i].desc<<endl;
}else cout<<"无此客房号!\n";
break;
case 6:
while(cout<<"1.入住\n2.退房\n3.续住\n4.返回上层\n",cin>>SelSub){
switch(SelSub){
case 1:
cout<<"\n你好,请问要入住哪个客房?\n";
cin>>strIn;
for(i=0;i<cnt;++i)if(kfs[i].id==strIn)break;
if(i<cnt){
cout<<"\n该客房如下!:(客房号|客房状态|客房等级|客房描述)\n";
cout<<kfs[i].id<<'|'<<kfs[i].state<<'|'<<kfs[i].level<<'|'<<kfs[i].desc<<endl;
if(kfs[i].state=="空"){
cout<<"确定要入住吗?(y/n)\n";
cin>>strIn;
if(strIn=="y"||strIn=="Y"){
kfs[i].state="入住";
t=time(NULL); //当前时间
kfs[i].local=*localtime(&t);//转化成当地时间存入记录
}
}else cout<<"\n此客房非空\n";
}else cout<<"无此客房号!\n";
break;
case 2:
cout<<"\n请输入你住的房间号:\n";
cin>>strIn;
for(i=0;i<cnt;++i)if(kfs[i].id==strIn)break;
if(i<cnt){
cout<<"\n该客房如下!:(客房号|客房状态|客房等级|客房描述)\n";
cout<<kfs[i].id<<'|'<<kfs[i].state<<'|'<<kfs[i].level<<'|'<<kfs[i].desc<<endl;
if(kfs[i].state!="空"){
cout<<"确定要退房吗?(y/n)\n";
cin>>strIn;
if(strIn=="y"||strIn=="Y"){
kfs[i].state="空";
t=time(NULL); //当前时间
locNow=*localtime(&t);
cntDay=locNow.tm_yday-kfs[i].local.tm_yday;
if(cntDay==0)cntDay=1;//不足1天算1天
if(locNow.tm_hour<12){
cout<<"\n早于中午12点!\n";
cout<<"\n你好,你的住宿费用是"<<(kfs[i].level*80+200)*cntDay<<endl;
}else{
cout<<"\n晚于中午12点,额外费用+50%\n";
cout<<"\n你好,你的住宿费用是"<<(kfs[i].level*80+200)*(cntDay+0.5)<<endl;
}
}
}else cout<<"\n此客房为空\n";
}else cout<<"无此客房号!\n";
break;
case 3:
cout<<"\n你好,请问要续住哪个客房?\n";
cin>>strIn;
for(i=0;i<cnt;++i)if(kfs[i].id==strIn)break;
if(i<cnt){
cout<<"\n该客房如下!:(客房号|客房状态|客房等级|客房描述)\n";
cout<<kfs[i].id<<'|'<<kfs[i].state<<'|'<<kfs[i].level<<'|'<<kfs[i].desc<<endl;
if(kfs[i].state=="入住"||kfs[i].state=="续住"){
cout<<"确定要续住吗?(y/n)\n";
cin>>strIn;
if(strIn=="y"||strIn=="Y"){
kfs[i].state="续住";
}
}else cout<<"\n此客房没被入住或续住,不能续住!\n";
}else cout<<"无此客房号!\n";
break;
case 4:
break;
default:
cout<<"\n输入非法\n";
}
if(SelSub==4)break;//返回上层
system("pause");
}
break;
case 7:
cout<<"\n谢谢使用!\n";
break;
default:
cout<<"\n输入非法\n";
}
if(Sel==7)break;
system("pause");
}
return 0;
}

效果图:

上一个:Visual C++ 安装失败
下一个:c++要怎样学

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,