|
|
|
@ -0,0 +1,404 @@
|
|
|
|
|
#define _CRT_SECURE_NO_WARNINGS
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <string.h> //在使用中要用到的字符串都包含在本文件中
|
|
|
|
|
#include <stdlib.h> //exit()函数就包含在此文件中
|
|
|
|
|
#include <conio.h>
|
|
|
|
|
#define isPrime(year) ((year%4==0&&year%100!=0)||(year%400==0))
|
|
|
|
|
|
|
|
|
|
int z[100]={0};
|
|
|
|
|
int s,j;
|
|
|
|
|
FILE *fp;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void check_in(); //声明登记入住函数
|
|
|
|
|
void availability(); //声明查询房间入住情况函数
|
|
|
|
|
void fate_days(); //声明查询日用住宿的费用
|
|
|
|
|
void fate_hours(); //声明查询时用住宿的费用
|
|
|
|
|
void check_out_days(); //声明结日用住宿的费用
|
|
|
|
|
void check_out_hours(); //声明结时用住宿的费用
|
|
|
|
|
void modificate(); //声明修改信息函数
|
|
|
|
|
void modificate_person(); //声明修改信息函数中的修改客户信息
|
|
|
|
|
void modificate_accommodation(); //声明修改信息函数中的修改住宿信息
|
|
|
|
|
void save(); //声明保存函数
|
|
|
|
|
void menu(); //声明菜单函数
|
|
|
|
|
void days(); //声明入住类型为天数函数
|
|
|
|
|
void hours(); //声明入住类型为小时函数
|
|
|
|
|
int date1Diff(); //声明计算天数差函数
|
|
|
|
|
|
|
|
|
|
struct date1
|
|
|
|
|
{
|
|
|
|
|
int year;
|
|
|
|
|
int month;
|
|
|
|
|
int day;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct Date
|
|
|
|
|
{int year;
|
|
|
|
|
int month;
|
|
|
|
|
int day;
|
|
|
|
|
int hour;
|
|
|
|
|
int minute;
|
|
|
|
|
}date; //定义日期变量
|
|
|
|
|
|
|
|
|
|
struct room
|
|
|
|
|
{
|
|
|
|
|
int room_ID; //房间号
|
|
|
|
|
int kind; //房间种类(包含单人间,双人间,三人间,VIP套房)
|
|
|
|
|
char name[20]; //客户姓名
|
|
|
|
|
int age; //客户年龄
|
|
|
|
|
int sex; //客户性别
|
|
|
|
|
char ID_card[20]; //客户身份证号
|
|
|
|
|
int day_money; //按日收费价格
|
|
|
|
|
int hour_money; //按小时收费价格
|
|
|
|
|
int count; //房间数量
|
|
|
|
|
struct Date date;
|
|
|
|
|
}room[100];
|
|
|
|
|
|
|
|
|
|
int main()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
printf("\n");
|
|
|
|
|
menu(); //把主菜单用函数来实现
|
|
|
|
|
save();
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void menu()
|
|
|
|
|
{
|
|
|
|
|
int n;
|
|
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
printf("\n");
|
|
|
|
|
printf(" \t ******************欢迎入住酒店***************** \n");
|
|
|
|
|
printf("\n *********************菜单********************");
|
|
|
|
|
printf("\n******* 1.登记入住 \t *******\n");
|
|
|
|
|
printf("******* 2.查询房间入住情况 \t *******\n");
|
|
|
|
|
printf("******* 3.查询当前费用(日用) \t *******\n");
|
|
|
|
|
printf("******* 4.查询当前费用(时用) \t *******\n");
|
|
|
|
|
printf("******* 5.结账当前费用(日用) \t *******\n");
|
|
|
|
|
printf("******* 6.结账当前费用(时用) \t *******\n");
|
|
|
|
|
printf("******* 7.退出 \t *******");
|
|
|
|
|
printf(" *********************菜单********************\n"); //输出菜单界面,让操作员能够方便的选择所需要进行的操作
|
|
|
|
|
printf("\n接下来的操作中,如果您的信息输入错误,请在下一步时输入0,则返回菜单,重新选择");
|
|
|
|
|
printf("\n请输入数字来选择操作:");
|
|
|
|
|
scanf("%d",&n);
|
|
|
|
|
while(n<1||n>7)
|
|
|
|
|
{printf(" *********************您输入的数字有误,请重新输入。********************\n");
|
|
|
|
|
scanf("%d",&n);}
|
|
|
|
|
switch(n)
|
|
|
|
|
{
|
|
|
|
|
case 1:check_in();break; //调用登记入住函数
|
|
|
|
|
case 2:availability();break; //调用查询房间的入住情况函数
|
|
|
|
|
case 3:fate_days();break; //调用查询当前日用费用函数
|
|
|
|
|
case 4:fate_hours();break; //调用查询当前时用费用函数
|
|
|
|
|
case 5:check_out_days();break; //调用结账日用费用函数
|
|
|
|
|
case 6:check_out_hours();break; //调用结账当前时用费用函数
|
|
|
|
|
case 7:exit(0); //退出
|
|
|
|
|
}
|
|
|
|
|
}while(n!=7);
|
|
|
|
|
scanf("%d",&n);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void check_in() // 登记函数
|
|
|
|
|
{
|
|
|
|
|
int op,way,po,i,num;
|
|
|
|
|
printf("请输入需要的房间数量:");
|
|
|
|
|
scanf("%d", &num); while(num<0||num>100)
|
|
|
|
|
{printf(" *********************您输入的数字有误,请重新输入。********************\n");
|
|
|
|
|
scanf("%d",&num);}
|
|
|
|
|
if(num==0) menu();
|
|
|
|
|
for (i=1;i<=num;++i) {
|
|
|
|
|
printf("请输入登记相关信息:\n");
|
|
|
|
|
printf("\n房间%d房号:(1号到100号之间)",i);
|
|
|
|
|
scanf("%d", &j);if(j==0) menu();
|
|
|
|
|
room[j].room_ID = j;
|
|
|
|
|
printf("\n请输入年龄:");
|
|
|
|
|
scanf("%d", &room[j].age);if(room[j].age==0) menu();
|
|
|
|
|
while (j<0||j>100)
|
|
|
|
|
{
|
|
|
|
|
printf("您的输入有误,请重新输入");
|
|
|
|
|
}
|
|
|
|
|
printf("\n请选择住宿时间类型:(1表示按天计费;2表示按小时计费)\n\t *****注意:如果您所居住时间包括了晚上,请您选择按天计费*****");
|
|
|
|
|
scanf("%d", &way);if(way==0) menu();
|
|
|
|
|
printf("\n入住时间为(年):");
|
|
|
|
|
scanf("%d", &room[j].date.year);if(room[j].date.year==0) menu();
|
|
|
|
|
printf("\n入住时间为(月):");
|
|
|
|
|
scanf("%d", &room[j].date.month);if(room[j].date.month==0) menu();
|
|
|
|
|
printf("\n入住时间为(日):");
|
|
|
|
|
scanf("%d", &room[j].date.day);if(room[j].date.day==0) menu();
|
|
|
|
|
if (way == 1)
|
|
|
|
|
{
|
|
|
|
|
printf("\n房间种类:[1代表单人间(200元/天);2代表双人间(390元/天);3代表三人间(475元/天);4代表VIP套房(650元/天)]");
|
|
|
|
|
scanf("%d", &op);if(op==0) menu();
|
|
|
|
|
}
|
|
|
|
|
if (way == 2)
|
|
|
|
|
{
|
|
|
|
|
printf("\n房间种类:[1代表单人间(10元/小时);2代表双人间(19元/小时);3代表三人间(27元/小时);4代表VIP套房(45元/小时)]");
|
|
|
|
|
scanf("%d", &po);if(po==0) menu();
|
|
|
|
|
printf("\n入住时间为(小时):");
|
|
|
|
|
scanf("%d", &room[j].date.hour);if(room[j].date.hour==0) menu();
|
|
|
|
|
printf("\n入住时间为(分钟):");
|
|
|
|
|
scanf("%d", &room[j].date.minute);if(room[j].date.minute==0) menu();
|
|
|
|
|
}
|
|
|
|
|
printf("\n姓名:");
|
|
|
|
|
scanf("%s", &room[j].name);if(room[j].name==0) menu();
|
|
|
|
|
printf("\n性别(其中:1表示男,2表示女!):");
|
|
|
|
|
scanf("%d", &room[j].sex);if(room[j].sex==0) menu();
|
|
|
|
|
printf("\n身份证号:");
|
|
|
|
|
scanf("%s", &room[j].ID_card);if(room[j].ID_card==0) menu();
|
|
|
|
|
z[j] = 1; //标记使用的房间为1
|
|
|
|
|
save();
|
|
|
|
|
}
|
|
|
|
|
menu();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void availability() //查询房间入住情况函数
|
|
|
|
|
{
|
|
|
|
|
int g,count=0;
|
|
|
|
|
for(g=0;g<100;g++)
|
|
|
|
|
{
|
|
|
|
|
if(z[g]==0)
|
|
|
|
|
++count;
|
|
|
|
|
else
|
|
|
|
|
if(z[g]==1)
|
|
|
|
|
printf("\n正在使用的房间号:%d",g);
|
|
|
|
|
}
|
|
|
|
|
printf("\n\n未使用的房间数:%d",count); //通过循环输出未使用的房间数
|
|
|
|
|
printf("\n\n");
|
|
|
|
|
printf("\n请输入需查询的房间号: "); //查询输入的房间号的信息,且输出该房间的相关信息
|
|
|
|
|
scanf("%d",&s);
|
|
|
|
|
while(s<0||s>100)
|
|
|
|
|
{printf(" *********************您输入的数字有误,请重新输入。********************\n");
|
|
|
|
|
scanf("%d",&s);}if(s==0) menu();
|
|
|
|
|
if(z[s]==1)
|
|
|
|
|
{printf("姓名:%s",room[s].name);
|
|
|
|
|
printf("\n性别(其中:1表示男,2表示女):%d",room[s].sex);
|
|
|
|
|
printf("\n年龄:%d",room[s].age);
|
|
|
|
|
printf("\n身份证号:%s",room[s].ID_card);
|
|
|
|
|
printf("\n年:%d",room[s].date.year);
|
|
|
|
|
printf(" 月:%d",room[s].date.month);
|
|
|
|
|
printf(" 日:%d",room[s].date.day);
|
|
|
|
|
printf("\n房间号:%d",room[s].room_ID);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
printf("该房间未被使用!");
|
|
|
|
|
menu();
|
|
|
|
|
save(); //调用保存函数
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void hours()
|
|
|
|
|
{
|
|
|
|
|
int nu,numb;
|
|
|
|
|
int hour1,minute1;
|
|
|
|
|
int hour2,minute2;
|
|
|
|
|
printf("请输入入住时间(小时,分钟)");
|
|
|
|
|
scanf("%d,%d",&hour1,&minute1);if(hour1==0||minute1==0) menu();
|
|
|
|
|
printf("请输入退房时间(小时,分钟)");
|
|
|
|
|
scanf("%d,%d",&hour2,&minute2);if(hour2==0||minute2==0) menu();
|
|
|
|
|
int t,t1,t2,o,q;
|
|
|
|
|
t1=hour1*60+minute1;
|
|
|
|
|
t2=hour2*60+minute2;
|
|
|
|
|
t=t2-t1;
|
|
|
|
|
o=t/60;
|
|
|
|
|
q=t%60;
|
|
|
|
|
if(q!=0)
|
|
|
|
|
o=o+1;
|
|
|
|
|
printf("您入住的小时为%d小时",o);
|
|
|
|
|
printf("\n您选择的房间类型是(1代表单人间,2代表双人间,3代表三人间,4代表VIP套房): ");
|
|
|
|
|
scanf("%d",&nu);if(nu==0) menu();
|
|
|
|
|
printf("\n您选择了几间套房: ");
|
|
|
|
|
scanf("%d",&numb);
|
|
|
|
|
while(numb<1||numb>7)
|
|
|
|
|
{printf(" *********************您输入的数字有误,请重新输入。********************\n");
|
|
|
|
|
scanf("%d",&numb);} if(numb==0) menu();
|
|
|
|
|
switch(nu)
|
|
|
|
|
{
|
|
|
|
|
case 1:printf("您当前费用为 %d 元",10*numb*o);break;
|
|
|
|
|
case 2:printf("您当前费用为 %d 元",19*numb*o);break;
|
|
|
|
|
case 3:printf("您当前费用为 %d 元",27*numb*o);break;
|
|
|
|
|
case 4:printf("您当前费用为 %d 元",45*numb*o);break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int date1Diff(struct date1 mindate,struct date1 maxdate)
|
|
|
|
|
{
|
|
|
|
|
int Days=0,j,flag;
|
|
|
|
|
const int primeMonth[][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}};
|
|
|
|
|
/************************************************************************/
|
|
|
|
|
/* 交换两个日期函数,将小的日期给mindate,将大的日期给maxdate */
|
|
|
|
|
/************************************************************************/
|
|
|
|
|
struct date1 tmp;
|
|
|
|
|
if ((mindate.year>maxdate.year)|| (mindate.year==maxdate.year&&mindate.month>maxdate.month)||(mindate.year==maxdate.year&&mindate.month==maxdate.month&&mindate.day>maxdate.day))
|
|
|
|
|
{
|
|
|
|
|
tmp=mindate;
|
|
|
|
|
mindate=maxdate;
|
|
|
|
|
maxdate=tmp;
|
|
|
|
|
}
|
|
|
|
|
/************************************************************************/
|
|
|
|
|
/* 从mindate.year开始累加到maxdate.year */
|
|
|
|
|
/************************************************************************/
|
|
|
|
|
for(j=mindate.year;j<maxdate.year;++j)
|
|
|
|
|
Days+=isPrime(j)?366:365; //如果maxdate.year是闰年,则flag=1,后面调用primeMonth[1][12]
|
|
|
|
|
flag=isPrime(maxdate.year); //加上maxdate.month到1月的天数
|
|
|
|
|
for (j=1;j<maxdate.month;j++)
|
|
|
|
|
Days+=primeMonth[flag][j-1]; //减去mindate.month到1月的天数
|
|
|
|
|
|
|
|
|
|
flag=isPrime(maxdate.year);
|
|
|
|
|
for (j=1;j<mindate.month;j++)
|
|
|
|
|
Days-=primeMonth[flag][j-1];
|
|
|
|
|
Days=Days+maxdate.day-mindate.day;
|
|
|
|
|
return Days;
|
|
|
|
|
}
|
|
|
|
|
void days()
|
|
|
|
|
{
|
|
|
|
|
int mun,un; // int isPrime(int year);
|
|
|
|
|
int date1Diff(struct date1 mindate,struct date1 maxdate);
|
|
|
|
|
struct date1 mindate,maxdate;
|
|
|
|
|
int Days;
|
|
|
|
|
printf("\t\t ***在输入日期过程中请不要让0在首位***");
|
|
|
|
|
printf("\n请输入入住日期(年,月,日):");
|
|
|
|
|
scanf("%i,%i,%i",&mindate.year,&mindate.month,&mindate.day);if(mindate.year==0||mindate.month==0||mindate.day==0) menu();
|
|
|
|
|
printf("请输入退房日期(年,月,日):");
|
|
|
|
|
scanf("%i,%i,%i",&maxdate.year,&maxdate.month,&maxdate.day);if(maxdate.year==0||maxdate.month==0||maxdate.day==0) menu();
|
|
|
|
|
Days=date1Diff(mindate,maxdate);
|
|
|
|
|
printf("您入住的天数为:%d\n",Days);
|
|
|
|
|
printf("\n您选择的房间类型是(1代表单人间,2代表双人间,3代表三人间,4代表VIP套房): ");
|
|
|
|
|
scanf("%d",&un);if(un==0) menu();
|
|
|
|
|
printf("\n您选择了几间套房: ");
|
|
|
|
|
scanf("%d",&mun); if(mun==0) menu();
|
|
|
|
|
switch(un)
|
|
|
|
|
{
|
|
|
|
|
case 1:printf("您当前费用为 %d 元",200*mun*Days);break;
|
|
|
|
|
case 2:printf("您当前费用为 %d 元",290*mun*Days);break;
|
|
|
|
|
case 3:printf("您当前费用为 %d 元",475*mun*Days);break;
|
|
|
|
|
case 4:printf("您当前费用为 %d 元",650*mun*Days);break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void fate_days()
|
|
|
|
|
{
|
|
|
|
|
days();
|
|
|
|
|
menu();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void fate_hours()
|
|
|
|
|
{
|
|
|
|
|
hours();
|
|
|
|
|
menu();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void check_out_days()
|
|
|
|
|
{
|
|
|
|
|
int Mun=0, Un,i; // int isPrime(int year);
|
|
|
|
|
int date1Diff(struct date1 mindate, struct date1 maxdate);
|
|
|
|
|
struct date1 mindate, maxdate;
|
|
|
|
|
int Days;
|
|
|
|
|
int roomId;
|
|
|
|
|
int roomNum;
|
|
|
|
|
|
|
|
|
|
printf("请输入房间数量:");
|
|
|
|
|
scanf("%i", &roomNum);if(roomNum==0) menu();
|
|
|
|
|
for (i = 1; i <= roomNum; ++i) {
|
|
|
|
|
while (1) {
|
|
|
|
|
printf("\n房间%d房号:(1号到100号之间)",i);
|
|
|
|
|
scanf("%i", &roomId);if(roomId==0) menu();
|
|
|
|
|
if (roomId < 0 || roomId >= 100) {
|
|
|
|
|
printf("房间号输入有误\n");
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
printf("\t\t ***在输入日期过程中请不要让0在首位***");
|
|
|
|
|
printf("\n请输入入住日期(年,月,日):");
|
|
|
|
|
scanf("%i,%i,%i", &mindate.year, &mindate.month, &mindate.day);if(mindate.year==0||mindate.month==0||mindate.day==0) menu();
|
|
|
|
|
printf("请输入退房日期(年,月,日):");
|
|
|
|
|
scanf("%i,%i,%i", &maxdate.year, &maxdate.month, &maxdate.day);if(maxdate.year==0||maxdate.month==0||maxdate.day==0) menu();
|
|
|
|
|
Days = date1Diff(mindate, maxdate);
|
|
|
|
|
printf("您入住的天数为:%d\n", Days);
|
|
|
|
|
printf("\n您选择的房间类型是(1代表单人间,2代表双人间,3代表三人间,4代表VIP套房): ");
|
|
|
|
|
scanf("%d", &Un);if(Un==0) menu();
|
|
|
|
|
switch (Un)
|
|
|
|
|
{
|
|
|
|
|
case 1:Mun+=(200*Days); break;
|
|
|
|
|
case 2:Mun += (290 * Days); break;
|
|
|
|
|
case 3:Mun+=(475*Days); break;
|
|
|
|
|
case 4:Mun += (650 * Days); break;
|
|
|
|
|
}
|
|
|
|
|
z[roomId] = 0;
|
|
|
|
|
memset(room + roomId, 0, sizeof(room));
|
|
|
|
|
}
|
|
|
|
|
printf("请缴纳 %d 元", Mun);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void check_out_hours()
|
|
|
|
|
{
|
|
|
|
|
int Nu, Numb = 0,i;
|
|
|
|
|
int hour1,minute1;
|
|
|
|
|
int hour2,minute2;
|
|
|
|
|
int roomId;
|
|
|
|
|
int roomNum;
|
|
|
|
|
printf("请输入房间数量:");
|
|
|
|
|
scanf("%i", &roomNum);if(roomNum==0) menu();
|
|
|
|
|
for (i = 1; i <= roomNum; ++i) {
|
|
|
|
|
while (1) {
|
|
|
|
|
printf("\n房间%d房号:(1号到100号之间)", i);
|
|
|
|
|
scanf("%i", &roomId);if(roomId==0) menu();
|
|
|
|
|
if (roomId < 0 || roomId >= 100) {
|
|
|
|
|
printf("房间号输入有误\n");
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
printf("请输入入住时间(小时,分钟)");
|
|
|
|
|
scanf("%d,%d", &hour1, &minute1);if(hour1==0||minute1==0) menu;
|
|
|
|
|
printf("请输入退房时间(小时,分钟)");
|
|
|
|
|
scanf("%d,%d", &hour2, &minute2);if(hour2==0||minute2==0) menu;
|
|
|
|
|
int t, t1, t2, o, q;
|
|
|
|
|
t1 = hour1 * 60 + minute1;
|
|
|
|
|
t2 = hour2 * 60 + minute2;
|
|
|
|
|
t = t2 - t1;
|
|
|
|
|
o = t / 60;
|
|
|
|
|
q = t % 60;
|
|
|
|
|
if (q != 0)
|
|
|
|
|
o = o + 1;
|
|
|
|
|
printf("您入住的小时为%d小时", o);
|
|
|
|
|
printf("\n您选择的房间类型是(1代表单人间,2代表双人间,3代表三人间,4代表VIP套房): ");
|
|
|
|
|
scanf("%d", &Nu);if(Nu==0) menu;
|
|
|
|
|
switch (Nu)
|
|
|
|
|
{
|
|
|
|
|
case 1:Numb+=(10*o);break;
|
|
|
|
|
case 2:Numb+=(19*o);break;
|
|
|
|
|
case 3:Numb+=(27*o);break;
|
|
|
|
|
case 4:Numb+=(45*o);break;
|
|
|
|
|
}
|
|
|
|
|
z[roomId]=0;
|
|
|
|
|
memset(room+roomId,0,sizeof(room));
|
|
|
|
|
}
|
|
|
|
|
printf("请缴纳 %d 元", Numb);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void save() //保存函数
|
|
|
|
|
{
|
|
|
|
|
FILE *fp;
|
|
|
|
|
int i;
|
|
|
|
|
if((fp=fopen("客房管理.txt","w+"))==NULL) //打开输出文件"客房管理.txt"
|
|
|
|
|
{printf("cannot open file\n");
|
|
|
|
|
exit(0);
|
|
|
|
|
}
|
|
|
|
|
for(i=0;i<100;i++)
|
|
|
|
|
{
|
|
|
|
|
if(fwrite((&room[i]), sizeof(room[100]),1,fp)!=1)
|
|
|
|
|
printf("file write error\n");
|
|
|
|
|
fflush(fp);
|
|
|
|
|
}
|
|
|
|
|
fclose(fp); //关闭文件
|
|
|
|
|
}
|