酒店客房管理系统
#include
#include
#include
#include
#define MAX 1000
typedef int Index;
typedef void Status;
Status weihu();
Status InputRoom();
Status writetotxt();
Status write1totxt();
Status readfromtxt();
Status read1fromtxt();
Index HashIndex(int num);
Status kefangxinxi();
Status xiugaikefang();
Status tainjiakefang();
Status shanchukefang();
Status zhusuguanli();
Status ruzhu();
Status tuifang();
Status xufang();
Status findprice();
Status findkefang();
Status findkeren();
Status findofroom();
Status findofname();
Status kerenxinxi();
Status daoqitixing();
typedef struct
{
int year;
int mon;
int day;
}ruzhutime;
typedef struct patron
{
int guenum;
char name[20];
char idnum[19];
char phone[12];
char sex[5];
ruzhutime time;
int timelong;
long int s;
}parton;
parton hash1[MAX];
typedef struct Guest
{
int guenum;
int maxnum;
int shifouruzhu;
double zujin;
int num;
}Guest;
Guest hash[MAX];
Index HashIndex(int num)
{
return num%MAX;
}
Status InputRoom()
{
int i;
printf("注意!!!是否继续,此操作会将原客房信息覆盖且无法恢复(Y/N)\n");
char choice;
scanf("%*c%c", &choice);
if(choice!='Y'&&choice!='y') return;
Guest room;
printf("请输入房间编号,(编号为-1时结束输入)\n");
while(scanf("%d", &room.guenum),room.guenum!=-1)
{
i=room.guenum%1000;
if(hash[i].guenum)
{
printf("已存在此房间!请重新输入!\n");
continue;
}
printf("请输入最大入住人数\n");
scanf("%d", &room.maxnum);
printf("请输入租金:\n");
scanf("%lf", &room.zujin);
printf("请输入是否有人入住:(1=有;0=没有)\n");
scanf("%d",&room.shifouruzhu);
printf("请输入入住人数:\n");
scanf("%d", &room.num);
hash[i]=room;
printf("请输入房间编号,(编号为-1时结束输入)\n");
}
printf("房间编号 最大入住人数 租金 是否有人 入住人数\n");
for(i=0;i<MAX;i++)
if(hash[i].guenum)
printf("%d %d %.2f %d %d\n", hash[i].guenum,hash[i].maxnum,hash[i].zujin,
hash[i].shifouruzhu,hash[i].num);
writetotxt();
}
Status weihu()
{
while(1)
{
printf("************************************\n");
printf("**** 重新输入客房信息请输入 1: ***\n");
printf("**** 修改客房信息请输入 2: ***\n");
printf("**** 添加客房信息请输入 3: ***\n");
printf("**** 删除客房信息请输入 4: ***\n");
printf("**** 返回上一菜单请输入 0: ***\n");
printf("************************************\n");
int n;
printf("请输入您的选择:\n");
if(scanf("%d", &n)!=1)
{
printf("输入错误!\n已退出!\n");
return;
}
switch(n)
{
case 1:InputRoom();break;
case 2:xiugaikefang();break;
case 3:tainjiakefang();break;
case 4:shanchukefang();break;
case 0:return;
}
}
}
Status shanchukefang()
{
int i,num;
printf("请输入要删除的客房编号:\n");
if(scanf("%d", &num)!=1)
{
printf("输入错误!\n已退出!\n");
return;
}
i=HashIndex(num);
if(!hash[i].guenum)
{
printf("此客房不存在!\n");
return ;
}
printf("删除不可恢复,是否要删除!Y/N\n");
char c;
if(scanf("%*c%c", &c)!=1)
{
printf("输入错误!\n已退出!\n");
return;
}
if(c!='Y'&&c!='y')
return;
hash[i].guenum=0;
writetotxt();
printf("删除成功!\n");
}
Status tainjiakefang()
{
int i,num;
printf("请输入需要添加的客房编号:\n");
if(scanf("%d", &num)!=1)
{
printf("输入错误!\n已退出!\n");
return;
}
i=HashIndex(num);
if(hash[i].guenum)
{
printf("此房间已存在!\n");
return;
}
hash[i].guenum=num;
printf("请输入最大入住人数\n");
scanf("%d", &hash[i].maxnum);
printf("请输入租金:\n");
scanf("%lf", &hash[i].zujin);
printf("请输入是否有人入住:(1=有;0=没有)\n");
scanf("%d",&hash[i].shifouruzhu);
printf("请输入入住人数:\n");
scanf("%d", &hash[i].num);
printf("添加成功!\n");
writetotxt();
}
Status xiugaikefang()
{
printf("请输入需要修改的客房的编号:\n");
int num,i,j;
scanf("%d", &num);
i=HashIndex(num);
if(!hash[i].guenum)
{
printf("不存在此房间!\n");
return;
}
printf("此房间信息为:\n");
printf("房间编号 最大入住人数 租金 是否有人 入住人数\n");
printf("%d %d %.2f %d %d\n", hash[i].guenum,hash[i].maxnum,hash[i].zujin,
hash[i].shifouruzhu,hash[i].num);
printf("是否要修改 是(Y)否(N)\n");
char c;
scanf("%*c%c", &c);
if(c!='y'&&c!='Y')
{
printf("修改取消!\n");
return;
}
printf("请输入最大入住人数\n");
scanf("%d", &hash[i].maxnum);
printf("请输入租金:\n");
scanf("%lf", &hash[i].zujin);
printf("请输入是否有人入住:(1=有;0=没有)\n");
scanf("%d",&hash[i].shifouruzhu);
printf("请输入入住人数:\n");
scanf("%d", &hash[i].num);
printf("修改成功!\n");
printf("修改后的信息为:\n");
printf("此房间信息为:\n");
printf("房间编号 最大入住人数 租金 是否有人 入住人数\n");
printf("%d %d %.2f %d %d\n", hash[i].guenum,hash[i].maxnum,hash[i].zujin,
hash[i].shifouruzhu,hash[i].num);
writetotxt();
}
Status kefangxinxi()
{
int i;
printf("房间编号 最大入住人数 租金 是否有人 入住人数\n");
for(i=0;i<MAX;i++)
if(hash[i].guenum)
printf("%d %d %.2f %d %d\n", hash[i].guenum,hash[i].maxnum,hash[i].zujin,
hash[i].shifouruzhu,hash[i].num);
}
Status search()
{
while(1)
{
printf("************************************\n");
printf("**** 查找客房信息请输入 1: ***\n");
printf("**** 查找客人信息请输入 2: ***\n");
printf("**** 浏览所有住房信息请输入 3: ***\n");
printf("**** 浏览所有客人信息请输入 4: ***\n");
printf("**** 筛选客房请输入输入 5: ***\n");
printf("**** 输出快到期的客人请输入 6: ***\n");
printf("**** 返回上一菜单请输入 0: ***\n");
printf("************************************\n");
int n;
printf("请输入您的选择:\n");
if(scanf("%d", &n)!=1)
{
printf("输入错误!\n已退出!\n");
return;
}
switch(n)
{
case 1:findkefang();break;
case 2:findkeren();break;
case 3:kefangxinxi();break;
case 4:kerenxinxi();break;
case 5:findprice();break;
case 6:daoqitixing();break;
case 0:return;
}
}
}
Status daoqitixing()
{
int i,j=0;
time_t rawtime;
printf("即将到期客人信息为:\n");
for(i=0;i<MAX;i++)
if(hash1[i].guenum)
if(hash1[i].s-time(&rawtime)<=hash1[i].timelong*24*60*60)
{
printf("%d %d %.2f %d %d\n", hash[i].guenum,hash[i].maxnum,hash[i].zujin,
hash[i].shifouruzhu,hash[i].num);
j=1;
}
if(!j) printf("不存在快到期的客人!\n");
}
Status findprice()
{
printf("请输入指定的价格区间:\n");
printf("请输入最小的价格:\n");
double low;
scanf("%lf", &low);
printf("请输入最大的价格:\n");
double high;
scanf("%lf", &high);
printf("请输入人数:\n");
int s;
scanf("%d",&s);
int i;
printf("房间编号 最大入住人数 租金 是否有人 入住人数\n");
for(i=0;i<MAX;i++)
if(hash[i].zujin>=low&&hash[i].zujin<=high&&hash[i].maxnum>=s)
printf("%d %d %.2f %d %d\n", hash[i].guenum,hash[i].maxnum,hash[i].zujin,
hash[i].shifouruzhu,hash[i].num);
}
Status kerenxinxi()
{
int i,j=0;
for(i=0;i<MAX;i++)
if(hash1[i].guenum)
{
printf("住宿房间号:%d 姓名:%s 身份证号:%s 电话号码: %s 性别: %s \n",hash1[i].guenum,hash1[i].name,
hash1[i].idnum,hash1[i].phone,hash1[i].sex);
j=1;
}
if(!j) printf("无人入住!\n");
}
Status findkeren()
{
int i,j=0;
printf("*********************************\n");
printf("**** 按照房间查找请输入 1 ****\n");
printf("**** 按照姓名查找请输入 2 ****\n");
printf("*********************************\n");
printf("请输入您的选择:\n");
int n;
scanf("%d", &n);
switch(n)
{
case 1:findofroom();break;
case 2:findofname();break;
}
}
Status findofname()
{
char name[20];
printf("请输入客人姓名:\n");
scanf("%s", name);
int i,j=0;
for(i=0;i<MAX;i++)
if(!strcmp(hash1[i].name,name))
{
printf("住宿房间号:%d 姓名:%s 身份证号:%s 电话号码: %s 性别: %s \n",hash1[i].guenum,hash1[i].name,
hash1[i].idnum,hash1[i].phone,hash1[i].sex);
j=1;
}
if(!j )printf("查无此人!!\n");
}
Status findofroom()
{
int i,num;
printf("请输入房间编号:\n");
scanf("%d", &num);
i=HashIndex(num);
if(!hash1[i].guenum)
{
printf("无人入住!!\n") ;
return;
}
printf("住宿房间号:%d 姓名:%s 身份证号:%s 电话号码: %s 性别: %s \n",hash1[i].guenum,hash1[i].name,
hash1[i].idnum,hash1[i].phone,hash1[i].sex);
}
Status findkefang()
{
int i,j=0;
printf("空余客房为:\n");
printf("房间编号 最大入住人数 租金 是否有人 入住人数\n");
for(i=0;i<MAX;i++)
if(!hash[i].shifouruzhu&&hash[i].guenum){
printf("%d %d %.2f %d %d\n", hash[i].guenum,hash[i].maxnum,hash[i].zujin,
hash[i].shifouruzhu,hash[i].num);
j=1;
}
if(!j) printf("客房爆满!!!\n");
}
Status zhusuguanli()
{
printf("************************************\n");
printf("***** 入住请输入 1: ****\n");
printf("***** 退房请输入 2: ****\n");
printf("***** 续房请输入 3: ****\n");
printf("***** 退出请输入 0: ****\n");
printf("************************************\n");
int n;
printf("请输入您的选择:\n");
scanf("%d", &n);
switch(n)
{
case 1:ruzhu();break;
case 2:tuifang();break;
case 3:xufang();break;
case 0:return;
}
}
Status xufang()
{
printf("请输入需要续房的房间号:\n");
int num,i;
if(scanf("%d", &num)!=1)
{
printf("输入错误!\n已退出!\n");
return;
}
i=HashIndex(num);
if(!hash1[i].guenum)
{
printf("此房间尚未租出!!\n");
return;
}
printf("住宿房间号:%d 姓名:%s 入住时间:%d年%d月%d日 入住时长:%d天\n",hash1[i].guenum,hash1[i].name,
hash1[i].time.year,hash1[i].time.mon,hash1[i].time.day,hash1[i].timelong);
printf("是否续费? Y/N\n");
char c;
if(scanf("%*c%c", &c)!=1)
{
printf("输入错误!\n已退出!\n");
return;
}
if(c!='y'&&c!='Y') return;
printf("请输入续费的天数:\n");
int day;
scanf("%d", &day) ;
hash1[i].timelong+=day;
printf("修改后的信息为:\n");
printf("住宿房间号:%d 姓名:%s 入住时间:%d年%d月%d日 入住时长:%d天\n",hash1[i].guenum,hash1[i].name,
hash1[i].time.year,hash1[i].time.mon,hash1[i].time.day,hash1[i].timelong);
write1totxt();
printf("续费成功!!\n");
}
Status tuifang()
{
printf("请输入将要退房的房间号:\n");
int num,i;
if(scanf("%d", &num)!=1)
{
printf("输入错误!\n已退出!\n");
return;
}
i=HashIndex(num);
if(!hash1[i].guenum)
{
printf("此房间没有租出!!\n");
return;
}
hash1[i].guenum=0;
write1totxt();
hash[i].shifouruzhu=0;
hash[i].num=0;
writetotxt();
printf("退房成功,欢迎下次光临!!!\n");
}
Status ruzhu()
{
findprice();
printf("请输入需要预定的房间编号:\n");
parton keren;
if(scanf("%d", &keren.guenum)!=1)
{
printf("输入错误!\n已退出!\n");
exit(0);
}
int i;
i=HashIndex(keren.guenum);
if(!hash[i].guenum)
{
printf("查无此房!!\n");
return;
}
if(hash[i].shifouruzhu)
{
printf("此房间已经有人!\n");
return;
}
int n;
printf("请输入几人入住:\n");
if(scanf("%d", &n)!=1)
{
printf("输入错误!\n已退出!\n");
return;
}
if(hash[i].maxnum<n)
{
printf("超过人数上限!!\n请重新输入:\n");
return;
}
printf("请输入客人姓名:\n");
scanf("%s", keren.name);
printf("请输入客人身份证号:\n");
scanf("%s", keren.idnum);
printf("请输入客人电话号码:\n");
scanf("%s", keren.phone);
printf("请输入客人性别:\n");
scanf("%s", keren.sex);
printf("请输入入住时间:(年月日),中间用空格隔开\n");
scanf("%d%d%d", &keren.time.year,&keren.time.mon,&keren.time.day);
printf("请输入入住时长:\n");
scanf("%d", &keren.timelong);
time_t rawtime;
keren.s=time(&rawtime);
hash1[i]=keren;
hash[i].shifouruzhu=1;
hash[i].num=n;
writetotxt();
write1totxt();
}
int main()
{
int i;
for(i=0;i<MAX;i++)
{
hash[i].guenum=0;
hash1[i].guenum=0;
}
readfromtxt();
read1fromtxt();
while(1)
{
printf("*************************************\n");
printf("**** 欢迎使用住宿管理系统 *****\n\n");
printf("**** 住宿管理请输入 1: *****\n");
printf("**** 客房管理请输入 2: *****\n");
printf("**** 查询统计请输入 3: *****\n");
printf("**** 退出请输入 0: *****\n\n");
printf("*************************************\n");
int choice;
printf("请输入您的选择:\n");
if(scanf("%d",&choice)!=1)
{
printf("输入错误!\n已退出!\n");
exit(0);
}
switch(choice)
{
case 1:zhusuguanli();break;
case 2: weihu();break;
case 3:search();break;
case 0: printf("\n感谢使用本旅店管理系统\n\nhaut,掌握先进科技!\n");
exit(0);
}
}
return 0;
}
Status write1totxt()
{
FILE *fp;
fp=fopen("kerenxinxi.txt","w");
int i;
for(i=0;i<MAX;i++)
if(hash1[i].guenum)
fprintf(fp,"%d %s %s %s %s %d %d %d %d %d\n",hash1[i].guenum,hash1[i].name,hash1[i].idnum,hash1[i].phone,
hash1[i].sex,hash1[i].time.year,hash1[i].time.mon,hash1[i].time.day,hash1[i].timelong,hash1[i].s);
fclose(fp);
}
Status read1fromtxt()
{
parton keren;
FILE *fp;
fp=fopen("kerenxinxi.txt","r");
int i;
while(!feof(fp))
{
fscanf(fp,"%d %s %s %s %s %d %d %d %d %d\n", &keren.guenum,keren.name,keren.idnum,keren.phone,
keren.sex,&keren.time.year,&keren.time.mon,&keren.time.day,&keren.timelong,&keren.s);
i=HashIndex(keren.guenum);
hash1[i]=keren;
}
fclose(fp);
}
Status readfromtxt()
{
Guest room;
FILE *fp;
if((fp=fopen("roomxinxi.txt","r"))==NULL)
{
printf("打开文件失败!!!\n");
exit(0);
}
int i;
while(!feof(fp))
{
fscanf(fp,"%d %d %lf %d %d\n", &room.guenum,&room.maxnum,&room.zujin,
&room.shifouruzhu,&room.num);
i=HashIndex(room.guenum);
hash[i]=room;
}
if(fclose(fp))
{
printf("关闭文件失败!!!\n");
exit(0);
}
}
Status writetotxt()
{
int i;
FILE *fp;
if((fp=fopen("roomxinxi.txt","w"))==NULL)
{
printf("打开文件失败!!!\n");
exit(0);
}
for(i=0;i<MAX;i++)
if(hash[i].guenum)
fprintf(fp,"%d %d %lf %d %d\n", hash[i].guenum,hash[i].maxnum,hash[i].zujin,
hash[i].shifouruzhu,hash[i].num);
fclose(fp);
}