您好,欢迎访问三七文档
当前位置:首页 > 行业资料 > 酒店餐饮 > 第五组酒店客房预订管理系统的设计与实现源代码
#includeiostream#includeiomanip#includestring#includefstream#includeconio.h//输入/输出文件流类usingnamespacestd;constintMaxr=100;//最多的客户constintMaxb=100;//最多的客房constintMaxbor=10;//每位客户最多预订十间客房//person类classperson{public:charname[20];charID[18];char*getname(){returnname;}//获取姓名char*getID(){returnID;}//获取身份证号voidsetID(charI[])//设置身份证号{strcpy(ID,I);}voidsetname(charna[])//设置姓名{strcpy(name,na);}};//客户类公有继承了person类,实现对客户的信息的描述classcustomer:publicperson{private:intnum;//客户编号inttag;//删除标记1:已删0:未删intborbook[Maxbor];//所订房间public:customer(){}intgettag(){returntag;}//获取删除标记voiddelbook(){tag=1;}//设置删除标记1:已删0:未删intgetnum(){returnnum;}//获取客户编号voidaddcustomer(intn,char*na,char*I)//增加客户{tag=0;num=n;strcpy(name,na);strcpy(ID,I);for(inti=0;iMaxbor;i++)borbook[i]=0;}voidborrowbook(intbookid)//预订操作{for(inti=0;iMaxbor;i++){if(borbook[i]==0){borbook[i]=bookid;return;}}}intretbook(intbookid)//退订操作{for(inti=0;iMaxbor;i++){if(borbook[i]==bookid){borbook[i]=0;return1;}}return0;}voiddisplay()//读出客户信息{cout客户编号:numsetw(15)姓名:namesetw(15)身份证号:IDsetw(15)客房编号:[;for(inti=0;iMaxbor;i++)if(borbook[i]!=0)cout#borbook[i];cout]endl;}};//客户库类,实现建立客户的个人资料classRDatabase{private:inttop;//客户记录指针customerread[Maxr];//客户记录public:RDatabase()//构造函数,将customer.txt读到read[]中{customers;top=-1;fstreamfile(customer.txt,ios::in);//打开一个输入文件while(1){file.read((char*)&s,sizeof(s));if(!file)break;top++;read[top]=s;}file.close();//关闭customer.txt}voidclear()//删除所有客户信息{top=-1;}intaddcustomer(intn,char*na,char*I)//添加客户时先查找是否存在{customer*p=query(n);if(p==NULL){top++;read[top].addcustomer(n,na,I);return1;}return0;}customer*query(intcustomerid)//按编号查找{for(inti=0;i=top;i++)if(read[i].getnum()==customerid&&read[i].gettag()==0){return&read[i];}returnNULL;}customer*query(stringname)//按name查找{for(inti=0;i=top;i++)if(read[i].getname()==name&&read[i].gettag()==0){return&read[i];}returnNULL;}voiddisplay()//输出所有客户信息{for(inti=0;i=top;i++)if(read[i].gettag()==0)read[i].display();}voidcustomerdata();//客户库维护~RDatabase()//析构函数,将read[]写到customer.txt文件中{fstreamfile(customer.txt,ios::out);for(inti=0;i=top;i++)if(read[i].gettag()==0)file.write((char*)&read[i],sizeof(read[i]));file.close();}};voidRDatabase::customerdata(){charchoice;charrsex[10];charrname[20];intcustomerid;charrID[18];customer*r;system(cls);while(choice!='0'){coutendlsetw(40)客户信息endl;coutendlsetw(28)1新增endl;coutendlsetw(28)2更改endl;coutendlsetw(28)3删除endl;coutendlsetw(28)4查找endl;coutendlsetw(28)5显示endl;coutendlsetw(28)6全删endl;coutendlsetw(28)0返回endl;cinchoice;system(cls);switch(choice){case'1':cout请输入客户信息:endl;cout输入客户编号:;cincustomerid;cout输入客户姓名:;cinrname;cout输入客户身份证号:;cinrID;addcustomer(customerid,rname,rID);break;case'2':cout输入客户编号:;cincustomerid;r=query(customerid);if(r==NULL){cout该客户不存在endl;break;}cout输入新的客户姓名:;cinrname;r-setname(rname);cout输入新的身份证号码:;cinrID;r-setID(rID);break;case'3':cout输入客户编号:;cincustomerid;r=query(customerid);if(r==NULL){cout该客户不存在endl;break;}r-delbook();cout删除成功!endl;break;case'4':charcho;cout请选择查找方式:endl;cout1.按客户编号查找,2.按客户姓名查找;cincho;system(cls);switch(cho){case'1':cout输入客户编号:;cincustomerid;r=query(customerid);if(r==NULL){cout该客户不存在endl;break;}break;case'2':cout输入客户名字:;cinrname;r=query(rname);if(r==NULL){cout该客户不存在endl;break;}}r-display();break;case'5':display();break;case'6':clear();cout删除成功!endl;break;default:cout正在返回主界面...;system(cls);break;}}}//客房类,实现对客房的描述classBook{private:inttag;//删除标记1:已删0:未删intno;//客房编号charname[20];//客房描述intonshelf;//是否预订1:空房2:已预订public:Book(){}char*getname(){returnname;}//获取姓名intgetno(){returnno;}//获取客房编号intgettag(){returntag;}//获取删除标记voidsetname(charna[])//设置客房描述{strcpy(name,na);}voiddelbook(){tag=1;}//删除客房voidaddbook(intn,char*na)//增加客房{tag=0;no=n;strcpy(name,na);onshelf=1;}intborrowbook()//预订操作{if(onshelf==1){onshelf=0;return1;}return0;}voidretbook()//退订操作{onshelf=1;}voiddisp()//输出客房{cout客房编号:nosetw(15)客房描述:namesetw(15)(onshelf==1?空房:已预订)endl;}};//客房库类,实现对客房的管理,如查找、删除等classBDatabase{private:inttop;//客房记录指针Bookbook[Maxb];//客房记录public:BDatabase()//构造函数,将book.txt读到book[]中{Bookb;top=-1;fstreamfile(book.txt,ios::in);while(1){file.read((char*)&b,sizeof(b));if(!file)break;top++;book[top]=b;}file.close();}voidclear()//全删{top=-1;}intaddbook(intn,char*na)//增加客房{Book*p=query(n);if(NULL==p){top++;book[top].addbook(n,na);return1;}return0;}Book*query(intbookid)//查找客房{for(inti=0;i=top;i++)if(book[i].getno()==bookid&&book[i].gettag()==0){return&book[i];}returnNULL;}Book*query(stringbname){for(inti=0;i=top;i++)if(book[i].getname()==bname&&book[i].gettag()==0){return&book[i];}returnNULL;}voidbookdata();//客房库维护voiddisp(){for(inti=0;i=top;i++)if(book[i].gettag()==0)book[i].disp();}~BDatabase()//析构函数,将book[]写到book.txt文件中{fstreamfile(book.txt,ios::out);for(inti=0;i=top;i++)if(book[i].gettag()==0)file.write((char*)&book[i],sizeof(book[i]));file.close();}};voidBDatabase::bookdata()
本文标题:第五组酒店客房预订管理系统的设计与实现源代码
链接地址:https://www.777doc.com/doc-1876954 .html