|
|
#include<string.h>
|
|
|
#include<stdlib.h>
|
|
|
#include<stdio.h>
|
|
|
#include<conio.h>
|
|
|
typedef struct tagCustomer
|
|
|
{
|
|
|
char m_ID[19]; /*身份证号码*/
|
|
|
char m_name[10]; /*顾客姓名*/
|
|
|
int m_age; /*顾客年龄*/
|
|
|
char m_sex[6]; /*顾客性别*/
|
|
|
int num;
|
|
|
}Customer; /*顾客结构*/
|
|
|
|
|
|
typedef struct tagRoom
|
|
|
{
|
|
|
int m_num; /*房间号*/
|
|
|
int m_floor; /*楼层*/
|
|
|
int m_price; /*价格*/
|
|
|
int m_use; /*是否已入住*/
|
|
|
}Room; /*房间结构*/
|
|
|
int i,j=0,age,num,floor,price,use,n;
|
|
|
int reg =0;
|
|
|
Customer cus[5];
|
|
|
Room r[5];
|
|
|
int count=5;
|
|
|
char ID[18],name[10],sex[6];
|
|
|
FILE *fproom;
|
|
|
FILE *fpcustomer; /*函数定义部分*/
|
|
|
|
|
|
void dengji() /*顾客登记部分*/
|
|
|
{
|
|
|
if(count<=5)
|
|
|
{
|
|
|
printf("请输入身份证号(18位数字):");
|
|
|
scanf("%s",&cus[j].m_ID);
|
|
|
printf("请输入姓名(10位字符)");
|
|
|
scanf("%s",&cus[j].m_name);
|
|
|
printf("请输入年龄(数字型)");
|
|
|
scanf("%d",&cus[j].m_age);
|
|
|
printf("请输入性别(男或女):");
|
|
|
scanf("%s",&cus[j].m_sex);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
printf("\n 存储空间已满!");
|
|
|
}
|
|
|
printf("\n\r顾客可以住在:");
|
|
|
printf("\n\r房间号 楼层 价格 是否空闲(1:空闲0:已使用)");
|
|
|
for(i=0;i<count;i++)
|
|
|
{
|
|
|
if(r[i].m_use==1)
|
|
|
{
|
|
|
printf("\n\r%d %d %d %d ",r[i].m_num,r[i].m_floor,r[i].m_price,r[i].m_use);
|
|
|
}
|
|
|
}
|
|
|
printf("\n\r请你输入房间号:");
|
|
|
scanf("%d",&num);
|
|
|
reg = 0;
|
|
|
for(i=0;i<count;i++)
|
|
|
{
|
|
|
if(r[i].m_use==1&&r[i].m_num==num)
|
|
|
{
|
|
|
r[i].m_use = 0;
|
|
|
printf("\n 登记成功!\n");
|
|
|
cus[j].num=r[i].m_num ;
|
|
|
j=j+1;
|
|
|
reg=1;
|
|
|
}
|
|
|
}
|
|
|
if(reg==0)
|
|
|
{
|
|
|
printf("\n 登记失败!\n");
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
void chaxunxinxi() /*顾客信息部分*/
|
|
|
{
|
|
|
int t;
|
|
|
if(count<=5)
|
|
|
{
|
|
|
printf("按身份证查找请按1,按姓名查找请按2\n");
|
|
|
scanf ("%d",&t);
|
|
|
if(t==1)
|
|
|
{
|
|
|
printf("请输入身份证号(18位数字):");
|
|
|
scanf("%s",&ID);
|
|
|
for(i=0;i<count;i++)
|
|
|
{
|
|
|
if(strcmp(cus[i].m_ID,ID)==0)
|
|
|
{
|
|
|
printf("\n\r顾客身份证号:%s 姓名:%s 年龄:%d 性别:%s \n",cus[i].m_ID,cus[i].m_name,cus[i].m_age,cus[i].m_sex);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
if(t==2)
|
|
|
{
|
|
|
printf("请输入姓名:");
|
|
|
scanf("%s",&name);
|
|
|
for(i=0;i<count;i++)
|
|
|
{
|
|
|
if(strcmp(cus[i].m_name,name)==0)
|
|
|
{
|
|
|
printf("\n\r顾客身份证号:%s 姓名:%s 年龄:%d 性别:%s \n",cus[i].m_ID,cus[i].m_name,cus[i].m_age,cus[i].m_sex);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
printf("\n \n");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
void chaxunkongfangjian() /*查询空房间函数部分*/
|
|
|
{
|
|
|
printf("\n\r房间号 楼层 价格 是否空闲(1:空闲0:已使用)");
|
|
|
for(i=0;i<count;i++)
|
|
|
{
|
|
|
if(r[i].m_use==1)
|
|
|
{
|
|
|
printf("\n\r%d %d %d %d ",r[i].m_num,r[i].m_floor,r[i].m_price,r[i].m_use);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
void tuidingfangjian() /*顾客退订函数部分*/
|
|
|
{
|
|
|
int k;
|
|
|
printf("\n 请输入要退房顾客身份证:");
|
|
|
scanf("%s",&ID);
|
|
|
for(i=0;i<count;i++)
|
|
|
{
|
|
|
if(strcmp(cus[i].m_ID,ID)==0)
|
|
|
{
|
|
|
printf("\n\r顾客身份证号:%s 姓名:%s 年龄:%d 性别:%s \n\r已经成功退房!",cus[i].m_ID,cus[i].m_name,cus[i].m_age,cus[i].m_sex);
|
|
|
for(k=0;k<count;k++)
|
|
|
if(r[k].m_num==cus[i].num)
|
|
|
r[k].m_use=1;
|
|
|
memset(&cus[i],0,sizeof(Customer));
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
void baocuntuichu() /*保存退出函数部分*/
|
|
|
{
|
|
|
fproom=fopen("room","wb+");
|
|
|
fwrite((void *)&r,sizeof(Room),count,fproom);
|
|
|
fclose(fproom);
|
|
|
|
|
|
fpcustomer=fopen("customer","wb+");
|
|
|
fwrite((void *)&r,sizeof(Room),count,fpcustomer);
|
|
|
fclose(fpcustomer);
|
|
|
exit(0);
|
|
|
|
|
|
}
|
|
|
void feiyong() /*费用查询部分*/
|
|
|
{
|
|
|
printf("一楼价格100元每晚 \n");
|
|
|
printf("二楼价格200元每晚 \n");
|
|
|
printf("三楼价格300元每晚 \n");
|
|
|
printf("四楼价格400元每晚 \n");
|
|
|
printf("很遗憾,我们目前只开放一楼房间\n\n\n");
|
|
|
}
|
|
|
main() /*主函数*/
|
|
|
{
|
|
|
system("color f4");
|
|
|
fproom=fopen("room","wb");
|
|
|
if(fproom!=NULL)
|
|
|
{
|
|
|
for(i=0;i<count;i++)
|
|
|
{
|
|
|
int id=100;
|
|
|
r[i].m_num=i+100;
|
|
|
r[i].m_floor=1;
|
|
|
r[i].m_price=100;
|
|
|
r[i].m_use=1;
|
|
|
}
|
|
|
fwrite((void *)&r,sizeof(Room),count,fproom);
|
|
|
fclose(fproom);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
printf("\n---文件打开失败--");
|
|
|
} /*利用文件保存顾客信息及状态*/
|
|
|
for(;;)
|
|
|
{
|
|
|
|
|
|
printf("\n");
|
|
|
printf("╔═════════════════════╗\n");
|
|
|
printf("║ ║\n");
|
|
|
printf("║ 酒店管理系统 ║\n");
|
|
|
printf("║ 主菜单 ║\n");
|
|
|
printf("║ ║\n");
|
|
|
printf("║ 1.顾客登记 ║\n");
|
|
|
printf("║ 2.查询顾客信息 ║\n");
|
|
|
printf("║ 3.查询空房间 ║\n");
|
|
|
printf("║ 4.退订房间 ║\n");
|
|
|
printf("║ 5.保存并退出系统 ║\n");
|
|
|
printf("║ 6.费用查询 ║\n");
|
|
|
printf("║ ║\n");
|
|
|
printf("╚═════════════════════╝\n");
|
|
|
printf("请输入选择项(1-6):");
|
|
|
scanf("%d",&n);
|
|
|
printf("\n\n\n\n");
|
|
|
if(n>0&&n<=6)
|
|
|
{
|
|
|
switch(n)
|
|
|
{
|
|
|
case 1:dengji();break; /*顾客信息登记*/
|
|
|
case 2:chaxunxinxi();break; /*查询顾客信息*/
|
|
|
case 3:chaxunkongfangjian();break; /*查询空房间*/
|
|
|
case 4:tuidingfangjian();break; /*退订房间*/
|
|
|
case 5:baocuntuichu(); /*保存退出*/
|
|
|
case 6:feiyong();break; /*费用查询*/
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
printf("╔═════════════════════╗\n");
|
|
|
printf("║ ║\n");
|
|
|
printf("║ 输入错误! ║\n");
|
|
|
printf("║ 请退出! ║\n");
|
|
|
printf("║ ║\n");
|
|
|
printf("╚═════════════════════╝\n");
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|