C语言课程设计酒店房间登记与计费管理系统源代码.docx
《C语言课程设计酒店房间登记与计费管理系统源代码.docx》由会员分享,可在线阅读,更多相关《C语言课程设计酒店房间登记与计费管理系统源代码.docx(24页珍藏版)》请在冰点文库上搜索。
C语言课程设计酒店房间登记与计费管理系统源代码
酒店房间登记与计费管理系统源代码
#defineM80
#include
#include
#include
/*函数声明*/
voidcheck_in();/*登记入住函数*/
voidchamber();/*入住情况函数*/
voidprice();/*当前费用函数*/
voidfee();/*结账退房函数*/
voidinfor();/*信息查询函数*/
voidsave(int);/*保存信息函数*/
voidread(int);/*读取信息函数*/
voidchoice();/*功能选择函数*/
intjudge_year(int);/*判断闰年函数*/
voidinformation();/*输出全部房间信息*/
/*结构体*/
structtime
{intyear;
intmon;
intdate;
inthour;
};
structroom/*定义各房间信息的结构体*/
{charname[40];
charID[18];
intflag;/*0-无人入住,1-按小时计费,2-按天计费*/
longintdeposit;
timet[2];/*0-入住时间,1-当前时间*/
}room[M];
charc1[40]={0};
charc2[18]={0};
/*主函数(主界面)*/
voidmain()
{system("cls");/*清屏*/
system("color4E");
intn;
printf("********************************************************************************");
printf("****");
printf("**\t\t----------欢迎光临万豪酒店----------**");
printf("****");
printf("********************************************************************************\n\n");
printf("\t\t\t[1.登记入住]\n\n");
printf("\t\t\t[2.入住情况]\n\n");
printf("\t\t\t[3.当前费用]\n\n");
printf("\t\t\t[4.结账退房]\n\n");
printf("\t\t\t[5.信息查询]\n\n");
printf("\t\t\t[6.全部信息]\n\n");
printf("\t\t\t[7.退出系统]\n\n");
printf("请输入您需要的服务的代码:
");
scanf("%d",&n);
while(n<1||n>7)
{printf("\n\n代码输入有误,请您重新输入:
");
scanf("%d",&n);
}
switch(n)/*根据输入数字选择功能*/
{case1:
check_in();break;/*调用登记入住函数*/
case2:
chamber();break;/*调用房间情况函数*/
case3:
price();break;/*调用当前费用函数*/
case4:
fee();break;/*调用结账退房函数*/
case5:
infor();break;/*调用信息查询函数*/
case6:
information();break;/*调用全部信息函数*/
case7:
exit(0);/*调用退出系统函数*/
}
}
/*查看房间使用情况函数*/
voidchamber()
{system("cls");/*清屏*/
system("color4E");
printf("\n**********************************房间使用情况**********************************\n");
intcount=0;
inti;
intj;
intk;
intm;
for(i=1;i<=80;i++)/*统计未入住房间总数*/
{read(i);
if(room[i-1].flag==0)
count++;}
printf("当前未使用房间数:
%d\n\n\n",count);
chaxun:
printf("请输入你要查询的房间号(1-40:
单人间,41-80:
双人间):
");
/*输入房间号查询房间入住情况*/
scanf("%d",&m);
while(m<1||m>80)
{printf("\n\n房间号输入有误,请您重新输入:
");
scanf("%d",&m);
}
read(m);
while(room[m-1].flag!
=0)
{printf("\n\n对不起,该房间已有客人入住,请输入其他房间号:
");
scanf("%d",&m);
read(m);}
printf("\n\n该房间没有客人入住,您要入住该房间吗?
(1-是,2-否):
");
scanf("%d",&j);
while(j<1||j>2)
{printf("\n\n您的选择输入有误,请您重新输入:
");
scanf("%d",&j);
}
if(j==1)
check_in();
else
{printf("\n\n您需要继续查询吗?
(1-是,2-否):
");
scanf("%d",&k);
while(k<1||k>2)
{printf("\n\n您的选择输入有误,请您重新输入:
");
scanf("%d",&k);
}
if(k==1)
gotochaxun;
else
{printf("\n\n");
main();}
}
}
/*登记入住函数*/
voidcheck_in()
{system("cls");/*清屏*/
system("color4E");
inti;
intj;
intl;
intk;
inttab[2][12]={{31,28,31,30,31,30,31,31,30,31,30,31},
{31,29,31,30,31,30,31,31,30,31,30,31}};
printf("\n************************************登记入住************************************\n");
printf("请输入您将入住的房间号:
");
scanf("%d",&i);
while(i<1||i>80)
{printf("\n\n房间号输入有误,请您重新输入:
");
scanf("%d",&i);
}
read(i);
while(room[i-1].flag!
=0)/*判断房间是否入住*/
{printf("\n\n对不起,该房间已有客人入住,请输入其他房间号:
");
scanf("%d",&i);
read(i);}
printf("\n\n请输入您的姓名:
");/*客人信息登记*/
scanf("%s",room[i-1].name);
j=strlen(room[i-1].name);
while(j<0)
{printf("\n\n您的姓名输入有误,请您重新输入:
\n");
scanf("%s",room[i-1].name);
j=strlen(room[i-1].name);
}
printf("\n\n请输入您的证件号码:
");
scanf("%s",room[i-1].ID);
j=strlen(room[i-1].ID);
while(j!
=18)
{printf("\n\n您的证件号码输入有误,请您重新输入:
\n");
scanf("%s",room[i-1].ID);
j=strlen(room[i-1].ID);
}
if(i<=40)
{printf("\n\n您选择的是单人间,该房间148元/天,8元/小时。
\n\n\n");/*选择计费方式*/
printf("请选择您的计费方式(1:
按小时计费,2:
按天计费):
");
}
else
{printf("\n\n您选择的是双人间,该房间128元/天,7元/小时。
\n\n\n");
printf("请选择您的计费方式(1:
按小时计费,2:
按天计费):
");
}
scanf("%d",&room[i-1].flag);
while(room[i-1].flag<0||room[i-1].flag>2)
{printf("\n\n您的计费方式输入有误,请您重新输入:
");
scanf("%d",&room[i-1].flag);
}
printf("\n\n请按所示格式输入您的入住时间(年-月-日-时,时为24小时制):
");
scanf("%d-%d-%d-%d",&room[i-1].t[0].year,&room[i-1].t[0].mon,&room[i-1].t[0].date,&room[i-1].t[0].hour);
l=judge_year(room[i-1].t[0].year);
while((room[i-1].t[0].year<=0)||(room[i-1].t[0].mon<=0||room[i-1].t[0].mon>12)||(room[i-1].t[0].date<=0||room[i-1].t[0].date>tab[l][room[i-1].t[0].mon-1])||(room[i-1].t[0].hour<0||room[i-1].t[0].hour>=24))
{printf("\n\n您的入住时间输入有误,请按照格式重新输入:
");
scanf("%d-%d-%d-%d",&room[i-1].t[0].year,&room[i-1].t[0].mon,&room[i-1].t[0].date,&room[i-1].t[0].hour);
l=judge_year(room[i-1].t[0].year);
}
printf("\n\n请输入您的押金数额:
");
scanf("%ld",&room[i-1].deposit);
while(room[i-1].deposit<=0)
{printf("\n\n您的押金数额输入有误,请您重新输入:
\n");
scanf("%ld",&room[i-1].deposit);
}
printf("\n\n您是否确定您的信息:
(1-是,2-否):
");
scanf("%d",&k);
while(k<1||k>2)
{printf("\n\n您的选择输入有误,请您重新输入:
\n");
scanf("%d",&k);
}
if(k==1)
{printf("\n\n您已登记入住成功,祝您在本店住得愉快!
\n\n");
save(i);
choice();
}
else
check_in();
}
/*费用查询函数*/
voidprice()
{system("cls");/*清屏*/
system("color4E");
printf("\n************************************费用查询************************************\n");
inti;
intj;
intk;
inttab[2][12]={{31,28,31,30,31,30,31,31,30,31,30,31},
{31,29,31,30,31,30,31,31,30,31,30,31}};
intday=0;
inthr=0;
inttotal_hour;
inttotal_day;
longintprice;
printf("请输入您的房间号:
");
scanf("%d",&i);
while(i<1||i>80)
{printf("\n\n您的房间号输入有误,请您重新输入:
");
scanf("%d",&i);
}
read(i);
while(room[i-1].flag==0)/*判断房间是否已有客人入住*/
{printf("\n\n该房间无人入住,请重新输入您的房间号:
");
scanf("%d",&i);
read(i);
}
printf("\n\n请按所示格式输入当前时间(年-月-日-时,时为24小时制):
");/*输入当前时间*/
shuru:
scanf("%d-%d-%d-%d",&room[i-1].t[1].year,&room[i-1].t[1].mon,&room[i-1].t[1].date,&room[i-1].t[1].hour);
j=judge_year(room[i-1].t[1].year);
while((room[i-1].t[1].year<=0)||(room[i-1].t[1].mon<=0||room[i-1].t[1].mon>12)||(room[i-1].t[1].date<=0||room[i-1].t[1].date>tab[j][room[i-1].t[1].mon-1])||(room[i-1].t[1].hour<0||room[i-1].t[1].hour>=24))
{printf("\n\n您的入住时间输入有误,请按照格式重新输入:
");
scanf("%d-%d-%d-%d",&room[i-1].t[1].year,&room[i-1].t[1].mon,&room[i-1].t[1].date,&room[i-1].t[1].hour);
j=judge_year(room[i-1].t[1].year);
}
if(room[i-1].t[0].mon!
=room[i-1].t[1].mon)
{for(k=room[i-1].t[0].mon+1;k{day+=tab[j][k-1];
}
day+=tab[j][room[i-1].t[0].mon-1]-room[i-1].t[0].date+room[i-1].t[1].date;
}
else
{day+=room[i-1].t[1].date-room[i-1].t[0].date;}
hr=room[i-1].t[1].hour-room[i-1].t[0].hour;
if(room[i-1].flag==1)/*根据房间类型和计费方式计算费用*/
{if(hr<0)
{total_hour=day*24-hr;}
else
{total_hour=day*24+hr;}
if(i<=40)
price=8*total_hour;
else
price=7*total_hour;
}
if(room[i-1].flag==2)
{while(hr<0)
{day=day-1;hr=hr+24;}
if(hr<8)
{total_day=day;}
else
{total_day=day+1;}
if(i<=40)
price=148*total_day;
else
price=128*total_day;
}
while(price<0)
{printf("您的时间输入有误,请重新输入:
");
gotoshuru;
}
printf("\n\n当前费用为:
%ld元.\n\n",price);/*输出当前费用*/
choice();
}
/*结账退房函数*/
voidfee()
{system("cls");
system("color4E");
printf("\n************************************结账退房************************************\n");
inti;
intj;
intk;
inttab[2][12]={{31,28,31,30,31,30,31,31,30,31,30,31},
{31,29,31,30,31,30,31,31,30,31,30,31}};
intday=0;
inthr=0;
inttotal_hour;
inttotal_day;
longintprice;
longintfee;
printf("请输入您的房间号:
");
scanf("%d",&i);
while(i<1||i>80)
{printf("\n\n您的房间号输入有误,请您重新输入:
");
scanf("%d",&i);
}
read(i);
while(room[i-1].flag==0)/*判断房间是否有客人入住*/
{printf("\n\n该房间无人入住,请重新输入您的房间号:
");
scanf("%d",&i);
read(i);
}
printf("\n\n请按所示格式输入当前时间(年-月-日-时,时为24小时制):
");/*输入当前时间*/
shuru:
scanf("%d-%d-%d-%d",&room[i-1].t[1].year,&room[i-1].t[1].mon,&room[i-1].t[1].date,&room[i-1].t[1].hour);
j=judge_year(room[i-1].t[1].year);
while((room[i-1].t[1].year<=0)||(room[i-1].t[1].mon<=0||room[i-1].t[1].mon>12)||(room[i-1].t[1].date<=0||room[i-1].t[1].date>tab[j][room[i-1].t[1].mon-1])||(room[i-1].t[1].hour<0||room[i-1].t[1].hour>=24))
{printf("\n\n您的入住时间输入有误,请按照格式重新输入:
");
scanf("%d-%d-%d-%d",&room[i-1].t[1].year,&room[i-1].t[1].mon,&room[i-1].t[1].date,&room[i-1].t[1].hour);
j=judge_year(room[i-1].t[1].year);
}
if(room[i-1].t[0].mon!
=room[i-1].t[1].mon)
{for(k=room[i-1].t[0].mon+1;k{day+=tab[j][k-1];
}
day+=tab[j][room[i-1].t[0].mon-1]-room[i-1].t[0].date+room[i-1].t[1].date;
}
else
{day+=room[i-1].t[1].date-room[i-1].t[0].date;}
hr=room[i-1].t[1].hour-room[i-1].t[0].hour;
if(room[i-1].flag==1)/*根据房间类型和计费方式计算费用*/
{if(hr<0)
{total_hour=day*24-hr;}
else
{total_hour=day*24+hr;}
if(i<=40)
price=8*total_hour;
else
price=7*total_hour;
}
if(room[i-1].flag==2)
{while(hr<0)
{day=day-1;hr=hr+24;}
if(hr<8)
{total_day=day;}
else
{total_day=day+1;}
if(i<=40)
price=148*total_day;
else
price=128*total_day;
}
while(price<0)
{printf("您的时间输入有误,请重新输入:
");
gotoshuru;
}
fee=price-room[i-1].deposit;
if(fee>0)/*输出最后的总费用*/
{printf("\n\n扣除押金后,您另需支付费用%ld元。
",fee);}
elseif(fee==0)
{printf("\n\n您所交纳的押金恰好能够支付您的住房费用,您无需另行交钱。
");}
else
{printf("\n\n您所交纳的押金还未使用完,本宾馆应支付您余额%ld元。
",-fee);}
printf("\n\n\n您已退房成功,感谢您的光临,我们下次再见!
\n\n");
room[i-1].flag=0;
strcpy(room[i-1].name,c1);
strcpy(room[i-1].ID,c2);
room[i-1].deposit=0;
room[i-1].t[0].year=0;
room[i-1].t[0].mon=0;
room[i-1].t[0].date=0;
room[i-1].t[0].hour=0;
room[i-1].t[1].year=0;
room[i-1].t[1].mon=0;
room[i-1].t[1].date=0;
room[i-1].t[1].hour=0;
save(i);
choice();
}
/*信息查询函数*/
voidinfor()
{system("cls");
system("color4E");
printf("\n************************************信息查询************************************\n");
inti;
printf("请输入您的房间号:
");
scanf("%d",&i);
while(i<1||i>80)
{printf("\n\n您的房间号输入有误,请您重新输入:
");
scanf("%d",&i);
}
read(i);
while(room[i-1].flag==0)/*判断房间是否有客人入住*/
{printf("\n\n该房间无人入住,请重新输入您的房间号:
");
scanf("%d",&i);
read(i);
}
printf("\n\n您的信息如下:
\n\n\n");/*输出客人信息*/
printf("姓名:
");
puts(room[i-1].name);
printf("\n\n");
printf("证件号码:
");
puts(room[i-1].ID);
printf("\n\n");
printf("房间类型:
");
if(i<=40)
{printf("单人间\n\n\n");}
else
{printf("双人间\n\n\n");}
printf("计费方式:
");