C语言课程设计报告酒店房间登记及计费管理系统源代码.doc
. -酒店房间登记与计费管理系统源代码#define M 80#include<stdlib.h>#include<stdio.h>#include<string.h>/*函数声明*/void check_in(); /*登记入住函数*/void chamber(); /*入住情况函数*/void price(); /*当前费用函数*/void fee(); /*结账退房函数*/void infor(); /*信息查询函数*/void save(int); /*保存信息函数*/void read(int); /*读取信息函数*/ void choice(); /*功能选择函数*/int judge_year(int); /*判断闰年函数*/void information(); /*输出全部房间信息*/*构造体*/struct timeint year; int mon;int date;int hour; struct room /*定义各房间信息的构造体*/char name40;char ID18;int flag; /* 0-无人入住,1-按小时计费,2-按天计费 */long int deposit;time t2; /* 0-入住时间,1-当前时间 */ roomM;char c140=0;char c218=0;/*主函数主界面*/void main()system("cls"); /*清屏*/system("color 4E");int n;printf("*");printf("* *");printf("*tt - 欢送光临万豪酒店 - *");printf("* *");printf("*nn");printf("ttt 1. 登记入住 nn");printf("ttt 2. 入住情况 nn");printf("ttt 3. 当前费用 nn");printf("ttt 4. 结账退房 nn");printf("ttt 5. 信息查询 nn");printf("ttt 6. 全部信息 nn");printf("ttt 7. 退出系统 nn");printf("请输入您需要的效劳的代码:");scanf("%d",&n);while(n<1|n>7) printf("nn代码输入有误,请您重新输入:"); scanf("%d",&n); switch(n) /*根据输入数字选择功能*/ case 1:check_in();break; /*调用登记入住函数*/ case 2:chamber();break; /*调用房间情况函数*/ case 3:price();break; /*调用当前费用函数*/ case 4:fee();break; /*调用结账退房函数*/ case 5:infor();break; /*调用信息查询函数*/ case 6:information();break; /*调用全部信息函数*/ case 7:exit(0); /*调用退出系统函数*/*查看房间使用情况函数*/void chamber() system("cls"); /*清屏*/system("color 4E");printf("n*房间使用情况*n");int count=0;int i;int j;int k;int m;for(i=1;i<=80;i+) /*统计未入住房间总数*/read(i);if(roomi-1.flag=0) count+;printf("当前未使用房间数:%dnnn",count);chaxun:printf("请输入你要查询的房间号1-40:单人间,41-80:双人间:"); /*输入房间号查询房间入住情况*/scanf("%d",&m);while(m<1|m>80) printf("nn房间号输入有误,请您重新输入:"); scanf("%d",&m); read(m);while(roomm-1.flag!=0) printf("nn对不起,该房间已有客人入住,请输入其他房间号:"); scanf("%d",&m);read(m);printf("nn该房间没有客人入住,您要入住该房间吗?1-是,2-否:");scanf("%d",&j);while(j<1|j>2)printf("nn您的选择输入有误,请您重新输入:");scanf("%d",&j);if(j=1)check_in();elseprintf("nn您需要继续查询吗?1-是,2-否:");scanf("%d",&k);while(k<1|k>2)printf("nn您的选择输入有误,请您重新输入:");scanf("%d",&k);if(k=1)goto chaxun;elseprintf("nn");main();/*登记入住函数*/void check_in()system("cls"); /*清屏*/system("color 4E");int i;int j;int l;int k;int tab212=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("nn房间号输入有误,请您重新输入:"); scanf("%d",&i); read(i);while(roomi-1.flag!=0) /*判断房间是否入住*/ printf("nn对不起,该房间已有客人入住,请输入其他房间号:"); scanf("%d",&i);read(i);printf("nn请输入您的XX:"); /*客人信息登记*/scanf("%s",roomi-1.name);j=strlen(roomi-1.name);while(j<0)printf("nn您的XX输入有误,请您重新输入:n"); scanf("%s",roomi-1.name); j=strlen(roomi-1.name); printf("nn请输入您的证件:");scanf("%s",roomi-1.ID);j=strlen(roomi-1.ID);while(j!=18)printf("nn您的证件输入有误,请您重新输入:n"); scanf("%s",roomi-1.ID); j=strlen(roomi-1.ID); if(i<=40) printf("nn您选择的是单人间,该房间148元/天,8元/小时。nnn"); /*选择计费式*/ printf("请选择您的计费式1:按小时计费,2:按天计费:");else printf("nn您选择的是双人间,该房间128元/天,7元/小时。nnn"); printf("请选择您的计费式1:按小时计费,2:按天计费:");scanf("%d",&roomi-1.flag);while(roomi-1.flag<0|roomi-1.flag>2)printf("nn您的计费式输入有误,请您重新输入:");scanf("%d",&roomi-1.flag);printf("nn请按所示格式输入您的入住时间年-月-日-时,时为24小时制:");scanf("%d-%d-%d-%d",&roomi-1.t0.year,&roomi-1.t0.mon,&roomi-1.t0.date,&roomi-1.t0.hour);l=judge_year(roomi-1.t0.year);while(roomi-1.t0.year<=0)|(roomi-1.t0.mon<=0|roomi-1.t0.mon>12)|(roomi-1.t0.date<=0|roomi-1.t0.date>tablroomi-1.t0.mon-1)|(roomi-1.t0.hour<0|roomi-1.t0.hour>=24)printf("nn您的入住时间输入有误,请按照格式重新输入:");scanf("%d-%d-%d-%d",&roomi-1.t0.year,&roomi-1.t0.mon,&roomi-1.t0.date,&roomi-1.t0.hour);l=judge_year(roomi-1.t0.year);printf("nn请输入您的押金数额:");scanf("%ld",&roomi-1.deposit);while(roomi-1.deposit<=0)printf("nn您的押金数额输入有误,请您重新输入:n");scanf("%ld",&roomi-1.deposit);printf("nn您是否确定您的信息:1-是,2-否:");scanf("%d",&k);while(k<1|k>2)printf("nn您的选择输入有误,请您重新输入:n");scanf("%d",&k);if(k=1)printf("nn您已登记入住成功,祝您在本店住得愉快!nn");save(i);choice();elsecheck_in();/*费用查询函数*/void price()system("cls"); /*清屏*/system("color 4E");printf("n*费用查询*n");int i;int j;int k;int tab212=31,28,31,30,31,30,31,31,30,31,30,31,31,29,31,30,31,30,31,31,30,31,30,31;int day=0;int hr=0;int total_hour;int total_day;long int price;printf("请输入您的房间号:");scanf("%d",&i);while(i<1|i>80) printf("nn您的房间号输入有误,请您重新输入:"); scanf("%d",&i); read(i);while(roomi-1.flag=0) /*判断房间是否已有客人入住*/printf("nn该房间无人入住,请重新输入您的房间号:");scanf("%d",&i);read(i);printf("nn请按所示格式输入当前时间年-月-日-时,时为24小时制:"); /*输入当前时间*/shuru:scanf("%d-%d-%d-%d",&roomi-1.t1.year,&roomi-1.t1.mon,&roomi-1.t1.date,&roomi-1.t1.hour);j=judge_year(roomi-1.t1.year);while(roomi-1.t1.year<=0)|(roomi-1.t1.mon<=0|roomi-1.t1.mon>12)|(roomi-1.t1.date<=0|roomi-1.t1.date>tabjroomi-1.t1.mon-1)|(roomi-1.t1.hour<0|roomi-1.t1.hour>=24)printf("nn您的入住时间输入有误,请按照格式重新输入:");scanf("%d-%d-%d-%d",&roomi-1.t1.year,&roomi-1.t1.mon,&roomi-1.t1.date,&roomi-1.t1.hour);j=judge_year(roomi-1.t1.year);if(roomi-1.t0.mon!=roomi-1.t1.mon)for(k=roomi-1.t0.mon+1;k<roomi-1.t1.mon;k+)day+=tabjk-1;day+=tabjroomi-1.t0.mon-1-roomi-1.t0.date+roomi-1.t1.date;elseday+=roomi-1.t1.date-roomi-1.t0.date;hr=roomi-1.t1.hour-roomi-1.t0.hour;if(roomi-1.flag=1) /*根据房间类型和计费式计算费用*/if(hr<0)total_hour=day*24-hr;elsetotal_hour=day*24+hr;if(i<=40)price=8*total_hour;elseprice=7*total_hour;if(roomi-1.flag=2)while(hr<0)day=day-1;hr=hr+24;if(hr<8)total_day=day;elsetotal_day=day+1;if(i<=40)price=148*total_day;elseprice=128*total_day;while(price<0)printf("您的时间输入有误,请重新输入:");goto shuru;printf("nn当前费用为:%ld元.nn",price); /*输出当前费用*/choice();/*结账退房函数*/void fee()system("cls");system("color 4E");printf("n*结账退房*n");int i;int j;int k;int tab212=31,28,31,30,31,30,31,31,30,31,30,31,31,29,31,30,31,30,31,31,30,31,30,31; int day=0;int hr=0;int total_hour;int total_day;long int price;long int fee;printf("请输入您的房间号:");scanf("%d",&i);while(i<1|i>80) printf("nn您的房间号输入有误,请您重新输入:"); scanf("%d",&i); read(i);while(roomi-1.flag=0) /*判断房间是否有客人入住*/printf("nn该房间无人入住,请重新输入您的房间号:");scanf("%d",&i);read(i);printf("nn请按所示格式输入当前时间年-月-日-时,时为24小时制:"); /*输入当前时间*/shuru:scanf("%d-%d-%d-%d",&roomi-1.t1.year,&roomi-1.t1.mon,&roomi-1.t1.date,&roomi-1.t1.hour);j=judge_year(roomi-1.t1.year);while(roomi-1.t1.year<=0)|(roomi-1.t1.mon<=0|roomi-1.t1.mon>12)|(roomi-1.t1.date<=0|roomi-1.t1.date>tabjroomi-1.t1.mon-1)|(roomi-1.t1.hour<0|roomi-1.t1.hour>=24)printf("nn您的入住时间输入有误,请按照格式重新输入:");scanf("%d-%d-%d-%d",&roomi-1.t1.year,&roomi-1.t1.mon,&roomi-1.t1.date,&roomi-1.t1.hour);j=judge_year(roomi-1.t1.year);if(roomi-1.t0.mon!=roomi-1.t1.mon)for(k=roomi-1.t0.mon+1;k<roomi-1.t1.mon;k+)day+=tabjk-1;day+=tabjroomi-1.t0.mon-1-roomi-1.t0.date+roomi-1.t1.date;elseday+=roomi-1.t1.date-roomi-1.t0.date;hr=roomi-1.t1.hour-roomi-1.t0.hour;if(roomi-1.flag=1) /*根据房间类型和计费式计算费用*/if(hr<0)total_hour=day*24-hr;elsetotal_hour=day*24+hr;if(i<=40)price=8*total_hour;elseprice=7*total_hour;if(roomi-1.flag=2)while(hr<0)day=day-1;hr=hr+24;if(hr<8)total_day=day;elsetotal_day=day+1;if(i<=40)price=148*total_day;elseprice=128*total_day;while(price<0)printf("您的时间输入有误,请重新输入:");goto shuru;fee=price-roomi-1.deposit;if(fee>0) /*输出最后的总费用*/printf("nn扣除押金后,您另需支付费用%ld元。",fee);else if(fee=0)printf("nn您所交纳的押金恰好能够支付您的住房费用,您无需另行交。");elseprintf("nn您所交纳的押金还未使用完,本宾馆应支付您余额%ld元。",-fee);printf("nnn您已退房成功,感您的光临,我们下次再见!nn");roomi-1.flag=0;strcpy(roomi-1.name,c1);strcpy(roomi-1.ID,c2);roomi-1.deposit=0;roomi-1.t0.year=0;roomi-1.t0.mon=0;roomi-1.t0.date=0;roomi-1.t0.hour=0;roomi-1.t1.year=0;roomi-1.t1.mon=0;roomi-1.t1.date=0;roomi-1.t1.hour=0;save(i);choice();/*信息查询函数*/void infor()system("cls");system("color 4E");printf("n*信息查询*n");int i;printf("请输入您的房间号:");scanf("%d",&i);while(i<1|i>80) printf("nn您的房间号输入有误,请您重新输入:"); scanf("%d",&i); read(i);while(roomi-1.flag=0) /*判断房间是否有客人入住*/ printf("nn该房间无人入住,请重新输入您的房间号:");scanf("%d",&i);read(i);printf("nn您的信息如下:nnn"); /*输出客人信息*/printf("XX:");puts(roomi-1.name);printf("nn");printf("证件:");puts(roomi-1.ID);printf("nn");printf("房间类型:");if(i<=40)printf("单人间nnn");elseprintf("双人间nnn");printf("计费式:");if(roomi-1.flag=1)printf("按小时计费nnn");elseprintf("按天计费nnn");printf("入住时间:");printf("%d年%d%月%d日%d时nnn",roomi-1.t0.year,roomi-1.t0.mon,roomi-1.t0.date,roomi-1.t0.hour);printf("押金数额:");printf("%ld元nn",roomi-1.deposit);choice();/*功能选择函数*/void choice()printf("n*功能选择*n");printf("ttt 1. 入住情况 n");printf("ttt 2. 登记入住 n");printf("ttt 3. 当前费用 n");printf("ttt 4. 结账退房 n");printf("ttt 5. 信息查询 n");printf("ttt 6. 回主界面 n");printf("ttt 7. 全部信息 n");printf("ttt 8. 退出系统 n");int k;printf("请选择您需要的效劳:"); /*效劳选择*/scanf("%d",&k);while(k<1|k>8) printf("nn代码输入有误,请您重新输入:"); scanf("%d",&k); switch(k) case 1:chamber();break; /*调用房间情况函数*/ case 2:check_in();break; /*调用登记入住函数*/ case 3:price();break; /*调用当前费用函数*/ case 4:fee();break; /*调用结账退房函数*/ case 5:infor();break; /*调用信息查询函数*/ case 6:main();break; /*调用主函数*/ case 7:information();break; /*调用全部信息函数*/ case 8:exit(0); /*调用退出系统函数*/*判断闰年函数*/int judge_year(int x) if(x%4=0)&&(x%100!=0)|(x%400=0)return(1);elsereturn(0);/*全部信息查询*/void information() system("cls");printf("n*全部信息*n");int i;int j;int k;int year;int month;int date;int hour;int year1;int month1;int day1;int hour1;int tab212=31,28,31,30,31,30,31,31,30,31,30,31,31,29,31,30,31,30,31,31,30,31,30,31;int day=0;int hr=0;int total_hour;int total_day;long int price;printf("nn请按所示格式输入当前时间年-月-日-时,时为24小时制:"); /*输入当前时间*/scanf("%d-%d-%d-%d",&year,&month,&date,&hour);j=judge_year(year);for(i=1;i<=80;i+)read(i);if(roomi-1.flag=0)printf("房间%d无人入住。n",i);if(i<=40)printf("房间类型:单人间。n");printf("单价:148元/天,8元/小时。n");elseprintf("房间类型:双人间。n");printf("单价:128元/天,7元/小时。n");elseyear1=year-roomi-1.t0.year;month1=month-roomi-1.t0.mon;day1=date-roomi-1.t0.date;hour1=hour-roomi-1.t0.hour;while(hour1<0)day1=day1-1;hour1=hour1+24;printf("房间%d客户信息如下:n",i);printf("XX:");puts(roomi-1.name);printf("证件:");puts(roomi-1.ID);printf("房间类型:");if(i<=40)printf("单人间n");printf("单价:148元/天,8元/小时。n");elseprintf("双人间n");printf("单价:128元/天,7元/小时。n");printf("计费式:");if(roomi-1.flag=1)printf("按小时计费n");elseprintf("按天计费n");printf("入住时间:");printf("%d年%d%月%d日%d时n",roomi-1.t0.year,roomi-1.t0.mon,roomi-1.t0.date,roomi-1.t0.hour);printf("已入住时间:%d年%d月%d天%d小时。n",year1,month1,day1,hour1);printf("押金数额:");printf("%ld元",roomi-1.deposit);if(roomi-1.t0.mon!=month)for(k=roomi-1.t0.mon+1;k<month;k+)day+=tabjk-1;day+=tabjroomi-1.t0.mon-1-roomi-1.t0.date+date;elseday+=date-roomi-1.t0.date;hr=hour-roomi-1.t0.hour;if(roomi-1.flag=1) /*根据房间类型和计费式计算费用*/if(hr<0)total_hour=day*24-hr;elsetotal_hour=day*24+hr;if(i<=40)price=8*total_hour;elseprice=7*total_hour;if(roomi-1.flag=2)while(hr<0)day=day-1;hr=hr+24;if(hr<8)total_day=day;elsetotal_day=day+1;if(i<=40)price=148*total_day;elseprice=128*total_day;printf("n当前费用为:%ld元.n",price); /*输出当前费用*/day=0;hr=0; /*时间清零*/ choice();/*保存信息函数*/void save(int x)int i;char c;FILE *fp;if(fp=fopen("酒店房间登记与计费管理系统信息存储文件.txt","wb+")=NULL)printf("无法翻开文件。nnn");printf("请按任意键返回主菜单,并选择“退出系统选项,在修改错误后再运行此系统。nn