1、酒店管理程序设计
公管1102
亓升辉
#include
2、 for(y=0;y<5;y++) room[x][y]=0; } } void hotelTitle() { printf("\n-------酒店房间登记与计费管理系统----\n"); printf("\t1.登记入住\n"); printf("\t2.查询房间的入住情况\n"); printf("\t3.查询当前费用\n"); printf("\t4.结账退房\n"); printf("\t5.退出程序\n"); } void hotel_execute(); void hotel_select(); void ho
3、tel_outhotel(); void outsystem(); void hotel_total(); int main(void) { system("color f1"); init(); while(1) { Loop: hotelTitle(); printf("\n 请选择:"); j=scanf("%d",&k); if(j==0||k<1||k>5) { printf("\n 输入错误。\n\t 请输入所列出的选项。\n\n 3 秒后刷新...Please Weit! Thanks\
4、n"); fflush(stdin); //sleep(3000); system("cls"); goto Loop; } else { switch(k) { case 1: hotel_execute(); break; case 2: hotel_select(); break; case 3: hotel_total(); break; case 4: ho
5、tel_outhotel(); break; case 5: outsystem(); return 0; default: printf("\n\t 系统出错!请联系管理员!\n");//怕出现 BUG return 0; } } fflush(stdin); //清空缓存 } } //入住登记 } } void hotel_execute() { int x,y; printf("请输入你要住本酒店多少层楼的住房?【1-5】");
6、 fflush(stdin); L: scanf("%d",&x); p=x; if(x>5) { printf("不好意思本店没有该层楼房。\n 请重新选择:"); goto L; } printf("请输入你要住第%d 层的几号房间?【1-5】",x); fflush(stdin); LP: scanf("%d",&y); if(y>5) { printf("不好意思该层楼并无该房间。\n 请重新选择:");
7、 goto LP;//无条件的回去 GOTO 语句 } if(x>2) { //二层以上则 100 元一天 printf("\n 提示:该房是贵宾套房,100 元一天\n"); } else { printf("\n 提示:该房是标准套房,50 元一天\n"); } if(room[x-1][y-1]==0)//判断该房已经入住 { room[x-1][y-1]=1; printf("\n 谢谢您的光临,您已经成功登记。\
8、n 您的信息如下:\n 入住房间:%d-%d\n",x,y); start=clock(); } else { printf("警告:该房已经有人入住...请换房入住哈。\n"); } } //查询住房信息 void hotel_select() { int x,y,z; system("cls");//清空内容。 //以下没什么重要的。就是控制输出格式 printf("宾馆入住情况如下:"); printf("\n|-------|--------|----
9、\n"); printf("| |"); for(x=1;x<=5;x++) { printf("房间号 |"); } printf("\n"); for(x=0;x<5;x++) { if(x==0) { printf("|-------|--------|--------|--------|--------|--------|\n|第%d 层 |",x+1); }
10、 else { printf("\n|-------|--------|--------|--------|--------|--------|\n|第%d 层 |",x+1); } for(y=0;y<5;y++) { if(room[x][y]==0) { printf("空%d-%d |",x+1,y+1); } else { printf("住%d-%d |",x+1,y+1); }
11、 if(y+1==5) { if(x+1==1||x+1==2) printf(" 该层标间均 50 元"); else printf(" 该层标间均 100 元"); } } } printf("\n|-------|--------|--------|--------|--------|--------|\n"); printf("\n 住房信息:\n"); for(x=0,z=0;x<5;x++)
12、 { for(y=0;y<5;y++) { if(room[x][y]!=0) { z++; printf("\t%d-%d 有人入住\n",x+1,y+1); } } } if(z==0) { printf("\t 现无人入住本酒店...\n"); } } //结账 void hotel_outhotel() { int x=0,y=0; printf("请输
13、入您要结账退房的楼层编号?"); scanf("%d",&x); printf("请输入该楼层退房的房间编号?"); scanf("%d",&y); if(room[x-1][y-1]==1) { room[x-1][y-1]=0; printf("\n\t 房间%d-%d 退房成功,再会。\n",x,y); } else { printf("\n\t 房间%d-%d 退房失败。\n\t\t 原因:未入住,是空房,不需要退...再会。\n",x,y);
14、 } } //查看价钱 void hotel_total() { /*在 c 语言中有专门处理系统时间,程序计时等等功能的库,即 time.h 在 time.h 中函数 clock_t clock( void )可以完成计时功能。 这个函数返回从“开启这个程序进程”到“程序中调用 clock()函数”时之间的 CPU 时钟 计时单元(clock tick)数, 在 MSDN 中称之为挂钟时间(wal-clock) 。 其中 clock_t 是用来保存时间的数据类型,在 time.h 文件中,
15、 我们可以找到对它的定义: #ifndef _CLOCK_T_DEFINED typedef long clock_t; #define _CLOCK_T_DEFINED #endif 很明显, clock_t 是一个长整形数。 time.h 文件中, 在 还定义了一个常量 CLOCKS_PER_SEC, 它用来表示一秒钟会有多少个时钟计时单元, 其定义如下: #define CLOCKS_PER_SEC ((clock_t)1000) 可以看到每过千分之一秒(1 毫秒) , 调用 clock()函数返回的值就加 1。 */ c
16、lock_t finish=clock(); double duration = (double)(finish - start) / CLOCKS_PER_SEC; double day=duration/60/60/24;//这里是将秒换成天 double total=0; printf( "您住了%f 秒钟...\n",duration); //按任意键继续... system("pause"); if(p>2) { total=day*100; if(day==0) { tota
17、l=100; }
printf("\n 我们旅店是按包天计费的。\n 若按小时,您需要付%f 元,但是现在你要付 100 元(黑店哈哈)\n",total); //这种计费方式比较现实。符合实际
}
else
{
total=day*50;
if(day==0)
{total=50;}
printf("\n 我们旅店是按包天计费的。\n 若按小时,您需要付%f 元,但是现在你要付 50 元(黑店哈哈)\n",total);
}
} //退出
void outsystem()
{
char message[] = "\n 酒店登记计费系统.打造酒店中的名牌....";
int i,j;
j=strlen(message);
for(i=0;i






