酒店房间登记与计费管理系统
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<time.h>typedef struct _House
{int no;//房间号int flag;//是否入住char style[20];//房间标准float dayprice;//每天单价float hourprice;//每小时单价
}House;typedef struct _Record
{char name[20];//姓名int no;//房间号time_t time;//入住时间int style;//计费方式float price;//单价
}Record;//入住记录int AddInfo(Record rec[],int rnum,House house[],int hnum)
{int i,flag=0;system("cls");printf("请输入入住客人姓名:");scanf("%s",rec[rnum].name);printf("请输入入住房间号:");scanf("%d",&rec[rnum].no);for(i=0;i<hnum;i++)//根据房间号 查询是否有该房间 并查询是否已经有人入住{if(rec[rnum].no == house[i].no)//查询到房间{flag=1;//查询到房间if(house[i].flag==1)//已经有人入住{printf("该房间已有客人!入住失败!\n");system("pause");return rnum;//记录数量不变}break;}}if(flag==0)//没用该房间信息{printf("该房号不存在!入住失败!\n");system("pause");return rnum;//记录数量不变}//查询到 并且没人入住 说明可以入住house[i].flag=1;//设置有人入住rec[rnum].time=time(NULL);//获取当前时间printf("请选择计费方式(0:按天 1:按小时):");scanf("%d",&rec[rnum].style);if(rec[rnum].style==0)//根据计费方式 设置单价rec[rnum].price=house[i].dayprice;elserec[rnum].price=house[i].hourprice;printf("入住成功!\n");system("pause");return rnum+1;//记录数量增加
}int menu()
{int choice;system("cls");printf("1:登记入住\n");printf("2:查询房间\n");printf("3:查询费用\n");printf("4:结账退房\n");printf("5:房间信息\n");printf("6:入住信息\n");printf("0:退出\n");printf("请输入选择:");scanf("%d",&choice);return choice;
}void PrintRec(Record rec[],int rnum)
{int i;char ch[100];printf("%-10s%-10s%-20s%-10s%-10s\n","姓名","房间号","入住时间","计费方式","单价");for(i=0;i<rnum;i++){printf("%-10s",rec[i].name);printf("%-10d",rec[i].no);strftime(ch, 99, "%Y-%m-%d %H:%M:%S", localtime(&rec[i].time)); //年-月-日 时-分-秒 printf("%-20s",ch);if(rec[i].style==0){printf("%-10s","按天");}else{printf("%-10s","按小时");}printf("%-10g\n",rec[i].price);}
}int CalMoney(time_t in,time_t out,int style)
{long second=out-in;//计算经过多少秒if(style==0)//按天计算{ return (second%86400==0)?(second/86400):(second/86400+1);}//按小时计算 不能整除3600 多出来的按一小时算return (second%3600==0)?(second/3600):(second/3600+1);
}void CostNow(Record rec[],int rnum)
{int i,no,len;time_t nowtime;char ch[100];system("cls");printf("请输入要查询的房间号:");scanf("%d",&no);for(i=0;i<rnum;i++){if(rec[i].no==no){PrintRec(&rec[i],1);//输出当前记录信息nowtime=time(NULL);strftime(ch, 99, "%Y-%m-%d %H:%M:%S", localtime(&nowtime)); //年-月-日 时-分-秒 printf("当前时间:%s\n",ch);//根据入住时间和当前时间 计算费用len=CalMoney(rec[i].time,nowtime, rec[i].style);//计算时间长度printf("当前费用:%g\n",len*rec[i].price);//时间乘以单价break;}}if(i==rnum){printf("查询失败,该房间无人入住!\n");}system("pause");
}void PrintHouse(House house[],int hnum)
{int i;printf("%-10s%-10s%-10s%-10s%-10s\n","房间号","是否入住","房间类型","每天单价","每小时单价");for(i=0;i<hnum;i++){printf("%-10d",house[i].no);if(house[i].flag==0){printf("%-10s","否");}else{printf("%-10s","是");}printf("%-10s",house[i].style);printf("%-10g",house[i].dayprice);printf("%-10g\n",house[i].hourprice);}
}
//根据房间号查询房间信息
void SerachHouse(House house[],int hnum)
{int no,i;system("cls");printf("请输入要查询的房间号:");scanf("%d",&no);for(i=0;i<hnum;i++){if(house[i].no==no){PrintHouse(&house[i],1);//输出房间信息break;}}if(i==hnum){printf("无该房间号信息!\n");}system("pause");
}int DelRec(Record rec[],int rnum,House house[],int hnum)
{int i,no,len,j;time_t nowtime;char ch[100];system("cls");printf("请输入要退房的房间号:");scanf("%d",&no);for(i=0;i<rnum;i++){if(rec[i].no==no){PrintRec(&rec[i],1);//输出当前记录信息nowtime=time(NULL);strftime(ch, 99, "%Y-%m-%d %H:%M:%S", localtime(&nowtime)); //年-月-日 时-分-秒 printf("当前时间:%s\n",ch);//根据入住时间和当前时间 计算费用len=CalMoney(rec[i].time,nowtime, rec[i].style);//计算时间长度printf("需要付款:%g\n",len*rec[i].price);//时间乘以单价break;}}if(i==rnum){printf("查询失败,该房间无人入住!\n");system("pause");return rnum;}//存在就需要在记录里删除for(j=i;j<rnum;j++){rec[j]=rec[j+1];}for(i=0;i<hnum;i++)//找到房间 修改入住情况{if(house[i].no==no)house[i].flag=0;}printf("退房成功!\n");system("pause");return rnum-1;//记录-1
}int main()
{int choice;House house[]={{101,0,"单人间",100,20},{102,0,"单人间",100,20},{103,0,"单人间",100,20},{104,0,"标间",130,25},{105,0,"标间",130,25},{106,0,"标间",130,25},{107,0,"标间",130,25},{108,0,"双人间",150,40},{109,0,"双人间",150,40},{110,0,"双人间",150,40}};int hnum=sizeof(house)/sizeof(House);//得到房间的数量Record rec[100];//记录入住信息int rnum=0;//入住信息数量do{choice=menu();switch(choice){case 1:rnum=AddInfo(rec,rnum,house,hnum);break;case 2:SerachHouse(house,hnum);break;case 3:CostNow(rec,rnum);break;case 4:rnum=DelRec(rec,rnum,house,hnum);break;case 5:system("cls");PrintHouse(house,hnum);system("pause");break;case 6:system("cls");PrintRec(rec,rnum);system("pause");break;}}while(choice!=0);return 0;
}
酒店房间登记与计费管理系统
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<time.h>typedef struct _House
{int no;//房间号int flag;//是否入住char style[20];//房间标准float dayprice;//每天单价float hourprice;//每小时单价
}House;typedef struct _Record
{char name[20];//姓名int no;//房间号time_t time;//入住时间int style;//计费方式float price;//单价
}Record;//入住记录int AddInfo(Record rec[],int rnum,House house[],int hnum)
{int i,flag=0;system("cls");printf("请输入入住客人姓名:");scanf("%s",rec[rnum].name);printf("请输入入住房间号:");scanf("%d",&rec[rnum].no);for(i=0;i<hnum;i++)//根据房间号 查询是否有该房间 并查询是否已经有人入住{if(rec[rnum].no == house[i].no)//查询到房间{flag=1;//查询到房间if(house[i].flag==1)//已经有人入住{printf("该房间已有客人!入住失败!\n");system("pause");return rnum;//记录数量不变}break;}}if(flag==0)//没用该房间信息{printf("该房号不存在!入住失败!\n");system("pause");return rnum;//记录数量不变}//查询到 并且没人入住 说明可以入住house[i].flag=1;//设置有人入住rec[rnum].time=time(NULL);//获取当前时间printf("请选择计费方式(0:按天 1:按小时):");scanf("%d",&rec[rnum].style);if(rec[rnum].style==0)//根据计费方式 设置单价rec[rnum].price=house[i].dayprice;elserec[rnum].price=house[i].hourprice;printf("入住成功!\n");system("pause");return rnum+1;//记录数量增加
}int menu()
{int choice;system("cls");printf("1:登记入住\n");printf("2:查询房间\n");printf("3:查询费用\n");printf("4:结账退房\n");printf("5:房间信息\n");printf("6:入住信息\n");printf("0:退出\n");printf("请输入选择:");scanf("%d",&choice);return choice;
}void PrintRec(Record rec[],int rnum)
{int i;char ch[100];printf("%-10s%-10s%-20s%-10s%-10s\n","姓名","房间号","入住时间","计费方式","单价");for(i=0;i<rnum;i++){printf("%-10s",rec[i].name);printf("%-10d",rec[i].no);strftime(ch, 99, "%Y-%m-%d %H:%M:%S", localtime(&rec[i].time)); //年-月-日 时-分-秒 printf("%-20s",ch);if(rec[i].style==0){printf("%-10s","按天");}else{printf("%-10s","按小时");}printf("%-10g\n",rec[i].price);}
}int CalMoney(time_t in,time_t out,int style)
{long second=out-in;//计算经过多少秒if(style==0)//按天计算{ return (second%86400==0)?(second/86400):(second/86400+1);}//按小时计算 不能整除3600 多出来的按一小时算return (second%3600==0)?(second/3600):(second/3600+1);
}void CostNow(Record rec[],int rnum)
{int i,no,len;time_t nowtime;char ch[100];system("cls");printf("请输入要查询的房间号:");scanf("%d",&no);for(i=0;i<rnum;i++){if(rec[i].no==no){PrintRec(&rec[i],1);//输出当前记录信息nowtime=time(NULL);strftime(ch, 99, "%Y-%m-%d %H:%M:%S", localtime(&nowtime)); //年-月-日 时-分-秒 printf("当前时间:%s\n",ch);//根据入住时间和当前时间 计算费用len=CalMoney(rec[i].time,nowtime, rec[i].style);//计算时间长度printf("当前费用:%g\n",len*rec[i].price);//时间乘以单价break;}}if(i==rnum){printf("查询失败,该房间无人入住!\n");}system("pause");
}void PrintHouse(House house[],int hnum)
{int i;printf("%-10s%-10s%-10s%-10s%-10s\n","房间号","是否入住","房间类型","每天单价","每小时单价");for(i=0;i<hnum;i++){printf("%-10d",house[i].no);if(house[i].flag==0){printf("%-10s","否");}else{printf("%-10s","是");}printf("%-10s",house[i].style);printf("%-10g",house[i].dayprice);printf("%-10g\n",house[i].hourprice);}
}
//根据房间号查询房间信息
void SerachHouse(House house[],int hnum)
{int no,i;system("cls");printf("请输入要查询的房间号:");scanf("%d",&no);for(i=0;i<hnum;i++){if(house[i].no==no){PrintHouse(&house[i],1);//输出房间信息break;}}if(i==hnum){printf("无该房间号信息!\n");}system("pause");
}int DelRec(Record rec[],int rnum,House house[],int hnum)
{int i,no,len,j;time_t nowtime;char ch[100];system("cls");printf("请输入要退房的房间号:");scanf("%d",&no);for(i=0;i<rnum;i++){if(rec[i].no==no){PrintRec(&rec[i],1);//输出当前记录信息nowtime=time(NULL);strftime(ch, 99, "%Y-%m-%d %H:%M:%S", localtime(&nowtime)); //年-月-日 时-分-秒 printf("当前时间:%s\n",ch);//根据入住时间和当前时间 计算费用len=CalMoney(rec[i].time,nowtime, rec[i].style);//计算时间长度printf("需要付款:%g\n",len*rec[i].price);//时间乘以单价break;}}if(i==rnum){printf("查询失败,该房间无人入住!\n");system("pause");return rnum;}//存在就需要在记录里删除for(j=i;j<rnum;j++){rec[j]=rec[j+1];}for(i=0;i<hnum;i++)//找到房间 修改入住情况{if(house[i].no==no)house[i].flag=0;}printf("退房成功!\n");system("pause");return rnum-1;//记录-1
}int main()
{int choice;House house[]={{101,0,"单人间",100,20},{102,0,"单人间",100,20},{103,0,"单人间",100,20},{104,0,"标间",130,25},{105,0,"标间",130,25},{106,0,"标间",130,25},{107,0,"标间",130,25},{108,0,"双人间",150,40},{109,0,"双人间",150,40},{110,0,"双人间",150,40}};int hnum=sizeof(house)/sizeof(House);//得到房间的数量Record rec[100];//记录入住信息int rnum=0;//入住信息数量do{choice=menu();switch(choice){case 1:rnum=AddInfo(rec,rnum,house,hnum);break;case 2:SerachHouse(house,hnum);break;case 3:CostNow(rec,rnum);break;case 4:rnum=DelRec(rec,rnum,house,hnum);break;case 5:system("cls");PrintHouse(house,hnum);system("pause");break;case 6:system("cls");PrintRec(rec,rnum);system("pause");break;}}while(choice!=0);return 0;
}
发布评论