#include "Base.h"
#include "Villa.h"
#include "Hotel.h"
#include "Booking.h"
//-----1-----添加新旅馆的详细信息
void addHotel()
{
system("cls");
cout<<"ADD NEW HOTEL DETAILS"<<endl<<endl;
Hotel h1,h2;
int lastno = 0;
fstream hin("Hotel.dat",ios::in);
while(!hin.eof())
{
hin.read((char *)(&h1),sizeof(h1));
}
//循环读取文件,从而最后一条信息的编号
lastno = h1.getNo();
if (lastno <0)
{
lastno = 0;
}
hin.close();
//设置新的编号
h2.get(lastno);
fstream fout("Hotel.dat",ios::out|ios::app);
fout.write((char *)(&h2),sizeof(Hotel));
if (fout.fail())
{
cout<<"error accoured when writting!"<<endl;
return;
}
fout.close();
//新记录添加成功,提示友好信息
cout<<"successed writting new records into: Hotel.dat!"<<endl;
cout<<"Press enter to return menue!"<<endl;
system("pause");
}
//-----2-----添加别墅信息
void addVilla()
{
system("cls");
cout<<"ADD NEW RESORT DETAILS"<<endl<<endl;
int lastno = 0;
Villa v1,v2;
fstream vin("Villa.dat",ios::in);
//循环读取文件,从而最后一条信息的编号
while(!vin.eof())
{
vin.read((char *)(&v1),sizeof(v1));
lastno++;
}
vin.close();
//获取新的编号
v2.get(lastno - 1);
fstream vout("Villa.dat",ios::out|ios::app);
vout.write((char *)(&v2),sizeof(Villa));
if (vout.fail())
{
cout<<"error accoured when writting to Villa.dat!"<<endl;
return;
}
vout.close();
//新记录添加成功,提示友好信息
cout<<"successed writting new records into: Villa.dat!"<<endl;
cout<<"Press enter to return menue!"<<endl;
system("pause");
}
//-----H-----预定旅馆
/*void bookHotel()
{
system("cls");
int tmpno;
char tmptype;
bool find = false;
bool full = true;
cout<<"Enter Hotel code: ";
cin>>tmpno;
Hotel h1;
fstream fin("Hotel.dat",ios::in);
fin.read((char *)&h1,sizeof(Hotel));
while (!fin.eof())
{
if (tmpno == h1.getNo())
{
find = true;
break;
}
fin.read((char *)(&h1),sizeof(h1));
}
fin.close();
if (find)
{
cout<<"Enter required room type<'R' for regular , 'D' for deluxe> : ";
cin>>tmptype;
fstream fin("Hotel.dat",ios::in);
fin.read((char *)(&h1),sizeof(Hotel));
while (!fin.eof())
{
if ( (tmptype == 'R' || tmptype == 'r') && h1.getNo() == tmpno && h1.getStdar() >= 1)
{
full = false;
break;
}
if ( (tmptype == 'D' || tmptype == 'd') && h1.getNo() == tmpno && h1.getLux() >= 1)
{
full = false;
break;
}
fin.read((char *)&h1,sizeof(h1));
}
fin.close();
if (!full)
{
int lastno;
Booking bk1;
fstream bin("Booking.dat",ios::in);
while(!bin.eof())
{
bin.read((char *)(&bk1),sizeof(Booking));
}
bin.close();
lastno = bk1.getbkno();
if (lastno < 0) lastno = 0;
bk1.get(lastno,tmpno,tmptype);
fstream bout("Booking.dat",ios::out);
bout.write((char *)(&bk1),sizeof(Booking));
bout.close();
Hotel h[100];
int count = 0;
fstream hin("Hotel.dat",ios::in);
while(!hin.eof())
{
hin.read((char *)&h[count],sizeof(Hotel));
count++;
}
hin.close();
fstream hout("Hotel.dat",ios::out);
for(int i=0;i<count-1;++i)
{
if (h[i].getNo() == tmpno)
{
if (tmptype == 'R' || tmptype == 'r')
{
h[i].setStdar();
}
else if (tmptype == 'H' || tmptype == 'h')
{
h[i].setLux();
}
}
hout.write((char *)&h[i],sizeof(Hotel));
}
hout.close();
cout<<"Booking successed! press enter to return menue!"<<endl;
system("pause");
}
else
{
cout<<"sorry! no left Hotel! press enter to return menue"<<endl;
system("pause");
return;
}
}
else
{
cout<<"Hotel doesn't exist! press enter to return menue!"<<endl;
system("pause");
return;
}
}*/
/*//-----R----预定别墅
void bookVilla()
{
system("cls");
int tmpno;
char tmptype;
bool find = false;
bool full = true;
cout<<"Enter Resort code: ";
cin>>tmpno;
Villa v1;
fstream vin("Villa.dat",ios::in);
vin.read((char *)&v1,sizeof(Villa));
while (!vin.eof())
{
if (tmpno == v1.getNo())
{
find = true;
break;
}
vin.read((char *)(&v1),sizeof(v1));
}
vin.close();
if (find)
{
fstream vin("Villa.dat",ios::in);
vin.read((char *)(&v1),sizeof(Villa));
while (!vin.eof())
{
if ( v1.getNo() == tmpno && v1.getVilla() >= 1)
{
full = false;
break;
}
vin.read((char *)&v1,sizeof(v1));
}
vin.close();
if (!full)
{
int lastno;
Booking bk1;
fstream bin("Villabook.dat",ios::in);
while(!bin.eof())
{
bin.read((char *)(&bk1),sizeof(Booking));
}
bin.close();
lastno = bk1.getbkno();
if (lastno < 0) lastno = 0;
bk1.get(lastno,tmpno,tmptype);
fstream bout("Villabook.dat",ios::out);
bout.write((char *)(&bk1),sizeof(Booking));
bout.close();
Villa v[100];
int count = 0;
fstream vin("Villa.dat",ios::in);
while(!vin.eof())
{
vin.read((char *)&v[count],sizeof(Villa));
count++;
}
vin.close();
fstream vout("Villa.dat",ios::out);
for(int i=0;i<count-1;++i)
{
if (v[i].getNo() == tmpno)
{
v[i].setVilla();
}
vout.write((char *)&v[i],sizeof(Villa));
}
vout.close();
cout<<"Booking successed!"<<endl;
}
else
{
cout<<"sorry! no left Villa!"<<endl;
return;
}
}
else
{
cout<<"Villa doesn't exist!"<<endl;
return;
}
}*/
//-----3-----预定
void bookHotel()
{
system("cls");
int tmpno;
char tmptype;
bool find = false;
bool full = true;
cout<<"Enter Hotel code: ";
cin>>tmpno;
Hotel h1;
fstream fin("Hotel.dat",ios::in);
fin.read((char *)&h1,sizeof(Hotel));
while (!fin.eof())
{
if (tmpno == h1.getNo())
{
find = true;
break;
}
fin.read((char *)(&h1),sizeof(h1));
}
fin.close();
if (find)
{
cout<<"Enter required room type<'R' for regular , 'D' for deluxe> : ";
cin>>tmptype;
fstream fin("Hotel.dat",ios::in);
fin.read((char *)(&h1),sizeof(Hotel));
while (!fin.eof())
{
if ( (tmptype == 'R' || tmptype == 'r') && h1.getNo() == tmpno && h1.getStdar() >= 1)
{
full = false;
break;
}
if ( (tmptype == 'D' || tmptype == 'd') && h1.getNo() == tmpno && h1.getLux() >= 1)
{
full = false;
break;
}
fin.read((char *)&h1,sizeof(h1));
}
fin.close();
if (!full)
{
int lastno;
Booking bk1;
fstream bin("Booking.dat",ios::in);
while(!bin.eof())
{
bin.read((char *)(&bk1),sizeof(Booking));
}
bin.close();
lastno = bk1.getbkno();
if (lastno < 0) lastno = 0;
bk1.get(lastno,tmpno,tmptype);
fstream bout("Booking.dat",ios::out);
bout.write((char *)(&bk1),sizeof(Booking));
bout.close();
Hotel h[100];
int count = 0;
fstream hin("Hotel.dat",ios::in);
while(!hin.eof())
{
hin.read((char *)&h[count],sizeof(Hotel));
count++;
}
hin.close();
fstream hout("Hotel.dat",ios::out);
for(int i=0;i<count-1;++i)
{
if (h[i].getNo() == tmpno)
{
if (tmptype == 'R' || tmptype == 'r')
{
h[i].setStdar();
}
else if (tmptype == 'H' || tmptype == 'h')
{
h[i].setLux();
}
}
hout.write((char *)&h[i],sizeof(Hotel));
}
hout.close();
cout<<"Booking successed! press enter to return menue!"<<endl;
system("pause");
}
else
{
cout<<"sorry! no left Hotel! press enter to return menue"<<endl;
system("pause");
return;
}
}
else
{
cout<<"Hotel doesn't exist! press enter to return menue!"<<endl;
system("pause");
return;
}
/*char flag;
cout<<"Book Hotel or Resort?(H/R) :";
cin>>flag;
//-----H----预定旅馆
if (flag == 'H' || flag == 'h')
{
bookHotel();
}
//-----R----预�
没有合适的资源?快使用搜索试试~ 我知道了~
c++编写的旅馆预定系统
共34个文件
sbr:5个
cpp:5个
obj:5个
需积分: 3 25 下载量 87 浏览量
2008-12-08
19:12:49
上传
评论
收藏 1.31MB RAR 举报
温馨提示
用从c++编写的小型的旅馆预定系统,跟大家分享,请批评指正
资源推荐
资源详情
资源评论
收起资源包目录
bookhotel.rar (34个子文件)
bookhotel
Main.cpp 13KB
Hotel.h 936B
Hotel.dat 144B
Base.cpp 857B
Villa.dat 120B
bookhotel.ncb 65KB
bookhotel.dsp 5KB
Base.h 805B
bookhotel.plg 2KB
Hotel.cpp 1KB
bookhotel.opt 49KB
Debug
Booking.sbr 0B
vc60.pdb 116KB
Hotel.obj 249KB
Booking.obj 183KB
Base.sbr 0B
bookhotel.pdb 1.38MB
Villa.sbr 0B
vc60.idb 97KB
bookhotel.bsc 513KB
Base.obj 179KB
bookhotel.ilk 970KB
bookhotel.pch 2.15MB
Main.obj 339KB
Hotel.sbr 0B
bookhotel.exe 648KB
Villa.obj 247KB
Main.sbr 0B
Booking.h 972B
Villa.cpp 973B
booking.dat 144B
bookhotel.dsw 543B
Booking.cpp 903B
Villa.h 773B
共 34 条
- 1
资源评论
melody_roro
- 粉丝: 0
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功