1 / 26
文档名称:

C 版酒店管理程序代码.docx

格式:docx   大小:28KB   页数:26页
下载后只包含 1 个 DOCX 格式的文档,没有任何的图纸或源代码,查看文件列表

如果您已付费下载过本站文档,您可以点这里二次下载

分享

预览

C 版酒店管理程序代码.docx

上传人:woyaonulifacai 2021/10/27 文件大小:28 KB

下载得到文件列表

C 版酒店管理程序代码.docx

文档介绍

文档介绍:C++版酒店管理程序代码
C++版酒店管理程序代码
C++版酒店管理程序代码
程序代码
N:最终改进版代码(利用结构体储存多种类型的数据)
好处:比数组能储存更多类型的数据!
#include<iostream>
#include<string>
#include〈cstdlib>   //常用函数库
using namespace std;
/*在c++中struct和类的区别在于struct不能有方法,所有成员是public的*/
struct Room
{
int Number;
ﻩint Price;
ﻩint State;
ﻩint days;
ﻩstring Name;
string Phone;
ﻩstring ID;
};//room; 可以在声明struct的时候声明一个struct实例
Room room[80];
C++版酒店管理程序代码
C++版酒店管理程序代码
C++版酒店管理程序代码
class BookRoom     //定义预定房间类 
{
private:
ﻩﻩ
ﻩﻩstring cName; //顾客姓名
ﻩﻩint stayTime;   //预定天数
ﻩ int roomType;   //房间类型(1.标准单人间 2。大床房 3。标准双人间 4。 套房)
ﻩstring phoneNum;    // 预留手机号
ﻩﻩ
ﻩpublic:

void setData()
{
   string name;
ﻩ  int time;
   int type;
ﻩ string num;
ﻩ ﻩcout<<”您好,请输入您的姓名:"〈〈endl;cin>>name; cName=name;
ﻩﻩcout〈〈”预定天数为:”<<endl; cin>〉time; stayTime=time;
ﻩ ﻩcout<<"想要预定的房间类型:1。标准单人间 100/天 2.大床房 200/天 3.标准双人间 300/天 4.套房400/天”<<endl;cin〉〉type; roomType=type;
ﻩ ﻩcout〈〈”预留手机号:”<<endl;cin>>num; phoneNum=num;
ﻩ};
ﻩﻩvoid Book()
C++版酒店管理程序代码
C++版酒店管理程序代码
C++版酒店管理程序代码
ﻩ{
ﻩﻩcout<<”正在预定.。."<〈endl;
ﻩswitch(this->roomType)

case 1:for(int i=0;i〈20;i++)
ﻩ ﻩ{
ﻩﻩ if (room[i].State==0)      //房间无人占用且无人预定
ﻩﻩ{
ﻩ ﻩroom[i]。days=this-〉stayTime;
ﻩﻩﻩ room[i].Name=this->cName;
ﻩﻩﻩﻩ ﻩroom[i].Phone=this—>phoneNum;
ﻩﻩ ﻩ room[i].Price*=this—〉stayTime;
ﻩﻩ ﻩcout<〈"预定成功!房间号:”〈<room[i].Number〈<endl<〈endl;
ﻩ ﻩ room[i].State=1;break;   //已被预订 
ﻩﻩﻩ ﻩ}
ﻩ ﻩ else cout<<room[i].Number〈<"号房间已有人"<<endl;ﻩ
ﻩﻩﻩﻩ}break;
ﻩﻩ
ﻩ ﻩ case 2:for(int i=20;i<40;i++)
ﻩ {
ﻩﻩ    if(room[i]。State==0)
ﻩﻩ  {
ﻩ ﻩ   ﻩroom[i].days=this-〉stayTime;
C++版酒店管理程序代码
C++版酒店管理程序代码
C++版酒店管理程序代码
ﻩ ﻩ   ﻩroom[i]。Name=this—>cName;
ﻩ ﻩ room[i].Phone=this—>phoneNum;
ﻩﻩ room[i].Price*=this-〉stayTime;
ﻩﻩﻩ   cout〈<"预定成功!房间号:"<〈room[i].Number<<endl<<endl;
ﻩ room[i]。State=1; break;
ﻩﻩ }
ﻩ ﻩ   else cout<〈room[i].Number<<”号房间已有人”