兄弟我来迟了,不知道你回家了没,程序写好了,不知道符合要求不,贴上来大家指正指正吧。
微软编译器编译通过,运行正常。代码如下:
/*|------------------------|*/
/*|*******包含头文件*******|*/
/*|________________________|*/
#include <stdio.h>
#include <conio.h>
#include <malloc.h>
#include <ctype.h>
#include <dos.h>
#include <time.h>
#include <malloc.h>
/*|------------------------|*/
/*|******预定义标识符******|*/
/*|________________________|*/
#define SPACE ""
#define DEFAULTPATH "c:\\KFTZ.tz"
#define UP 72
#define DOWN 80
#define LEFT 75
#define RIGHT 77
#define ESC 27
#define ZERO 0
#define BLACK "0"
#define BLUE "1"
#define GREEN "2"
#define RED "4"
#define YELLOW "6"
#define WHITE "7"
#define LOAD "1"
#define SAVE "2"
#define CHECKIN "3"
#define CHECKOUT "4"
#define BOOK "5"
#define UNBOOK "6"
#define READY "7"
#define CQUERY "8"
#define MODIFY "9"
#define HQUERY "10"
#define REBUILD "11"
#define ADDHOUSE "12"
#define STATISTIC "13"
#define CLS "14"
#define MODICOLOR "15"
#define MENU "16"
#define HELP "17"
#define EXIT "18"
/*|------------------------|*/
/*|******枚举类型定义******|*/
/*|________________________|*/
enum housestatus
{EMPTY=0,BOOKED=1,CHECKEDIN=2}; /*房间状态*/
/*|------------------------|*/
/*|*******结构体定义*******|*/
/*|________________________|*/
struct Client
{
char Name[20];
char Sex[6];
char ID_card[20]; /*居民身份证*/
int year;
int month;
int day; /*住店时间*/
};
struct Hotel
{
char Room_ID[6]; /*房间号*/
char Tel[12];
unsigned Price;
enum housestatus Sing; /*标记房间是否为空房间*/
struct Client Client_list; /*实现两个结构体的嵌套*/
};
struct Rooms
{
struct Rooms *before;
struct Hotel theroom;
struct Rooms *next;
};
struct Roomp
{
struct Roomp *before;
struct Hotel *theroom;
struct Roomp *next;
};
struct Customers
{
struct Customers *before;
struct Client *thecustomer;
struct Customers *next;
};
/*|------------------------|*/
/*|********变量声明********|*/
/*|________________________|*/
char command[20];
char BGCOLOR[7]=BLACK;
char FORCOLOR[7]=WHITE;
char COLOR[3];
unsigned ROOMCNT=0;
unsigned ROOMREADY=0;
struct Rooms *ROOM=NULL;
struct Rooms *Roomtail=NULL;
char LOADPATH[50]=DEFAULTPATH;
char SAVEPATH[50]=DEFAULTPATH;
unsigned SAVED=1;
/*|------------------------|*/
/*|********函数声明********|*/
/*|________________________|*/
int year(); /*取当前系统时间的年份*/
int month(); /*取当前系统时间的月份*/
int day(); /*取当前系统时间的日期*/
void book(); /*预订房间*/
void unbook(); /*退订房间*/
void checkin(); /*开房*/
void checkout(); /*退房*/
void ready(); /*查看空房间*/
void statistic(); /*统计*/
void cquery(); /*房客查询*/
void hquery(); /*客户查询*/
void modify(); /*修改房客信息*/
void rebuild(); /*修改房间信息*/
void menu(); /*菜单*/
void dispmenu(); /*显示菜单*/
void flushstdin(); /*刷新输入缓冲区*/
void testsave(); /*当前台账是否保存*/
void addhouse(); /*新增房间*/
void load(); /*载入台账*/
void save(); /*保存台账*/
void cls(); /*清屏*/
void modicolor(); /*调整界面着色*/
void customerout(struct Hotel*); /*清除房间客人信息*/
void help(); /*显示帮助信息*/
int roomidexists(char *); /*房间号是否已存在*/
int telexists(char *); /*电话号码是否已存在*/
char *cmdtolower(char *cmd); /*命令转换为小写*/
struct Client registercustomer();/*登记房客*/
/*|------------------------|*/
/*|********函数定义********|*/
/*|________________________|*/
int year() /*取当前系统时间的年份*/
{
time_t tval;
struct tm *now;
tval=time(NULL);
now=localtime(&tval);
return now->tm_year+1900;
}
int month() /*取当前系统时间的月份*/
{
time_t tval;
struct tm *now;
tval=time(NULL);
now=localtime(&tval);
return now->tm_mon;
}
int day() /*取当前系统时间的日期*/
{
time_t tval;
struct tm *now;
tval=time(NULL);
now=localtime(&tval);
return now->tm_mday;
}
int roomidexists(char *roomid) /*房间号是否已存在*/
{
struct Rooms *HEAD=ROOM;
struct Rooms *CUSOR=HEAD;
if(CUSOR==NULL) return 0;
while(CUSOR!=NULL)
{
if(!strcmp(roomid,CUSOR->theroom.Room_ID)) return 1;
CUSOR=CUSOR->next;
}
return 0;
}
int telexists(char *tel) /*电话号码是否已存在*/
{
struct Rooms *HEAD=ROOM;
struct Rooms *CUSOR=HEAD;
if(CUSOR==NULL) return 0;
while(CUSOR!=NULL)
{
if(!strcmp(tel,CUSOR->theroom.Tel)) return 1;
CUSOR=CUSOR->next;
}
return 0;
}
void customerout(struct Hotel *r)/*清除房间客人信息*/
{
strcpy(r->Client_list.Name,"");
strcpy(r->Client_list.Sex,"");
strcpy(r->Client_list.ID_card,"");
r->Client_list.year=0;
r->Client_list.month=0;
r->Client_list.day=0;
}
struct Client registercustomer() /*登记房客*/
{
struct Client newcustomer;
printf("\t\t\t ======房客信息登记======\n");
printf("\n姓名:");
scanf("%s",newcustomer.Name);
printf("\n性别:");
scanf("%s",newcustomer.Sex);
printf("\n身份证号:");
scanf("%s",newcustomer.ID_card);
newcustomer.year=year();
newcustomer.month=month();
newcustomer.day=day();
return newcustomer;
}
void book() /*预订房间*/
{
char roomid[6]="";
struct Client customer;
struct Rooms *HEAD=ROOM;
struct Rooms *CUSOR=HEAD;
if(CUSOR==NULL)
{
printf("\n预订失败:酒店现无房间!\n");
return;
}
if(ROOMREADY==0)
{
printf("\n预订失败:酒店已无空房间!\n");
return;
}
customer=registercustomer();
while(1)
{
printf("\n预订房间号:");
scanf("%s",roomid);
cmdtolower(roomid);
if(!strcmp(roomid,"quit")) break;
HEAD=ROOM;
CUSOR=HEAD;
while(CUSOR!=NULL)
{
if(!strcmp(roomid,CUSOR->theroom.Room_ID)) break;
CUSOR=CUSOR->next;
}
if(CUSOR==NULL)
{
printf("\n预订失败:房间号不存在!\n");
continue;
}
if(CUSOR->theroom.Sing==EMPTY)
{
CUSOR->theroom.Sing=BOOKED;
CUSOR->theroom.Client_list=customer;
ROOMREADY--; /*空房间减一*/
SAVED=0;
printf("\n房间预订成功!\n");
break;
}
if(CUSOR->theroom.Sing==BOOKED)
{
printf("\n预订失败:该房间已被预订,请选择其他房间!\n");
continue;
}
if(CUSOR->theroom.Sing==CHECKEDIN)
{
printf("\n预订失败:该房间已有房客入住,请选择其他房间!\n");
continue;
}
}
}
void unbook() /*退订房间*/
{
char roomid[6]="";
char flag='x';
struct Client customer;
struct Rooms *HEAD=ROOM;
struct Rooms *CUSOR=HEAD;
if(CUSOR==NULL)
{
printf("\n退订失败:酒店现无房间!\n");
return;
}
if(ROOMREADY==ROOMCNT)
{
printf("\n预订失败:酒店目前尚无被预订房间!\n");
return;
}
while(1)
{
printf("\n退订房间号:");
scanf("%s",roomid);
cmdtolower(roomid);
if(!strcmp(roomid,"quit")) break;
HEAD=ROOM;
CUSOR=HEAD;
while(CUSOR!=NULL)
{
if(!strcmp(roomid,CUSOR->theroom.Room_ID)) break;
CUSOR=CUSOR->next;
}
if(CUSOR==NULL)
{
printf("\n退订失败:房间号不存在!\n");
continue;
}
if(CUSOR->theroom.Sing==BOOKED)
{
customer=CUSOR->theroom.Client_list;
printf("\n房间已找到,房间信息如下:\n");
printf("\t\t==============================================\n");
printf("\t\t 房间号 房间电话 房间价格 房间状态 \n");
printf("\t\t*--------------------------------------------*\n");
printf("\t\t %4s %7s %4u 已预订 \n",CUSOR->theroom.Room_ID,CUSOR->theroom.Tel,CUSOR->theroom.Price);
printf("\t\t==============================================\n");
printf("\n房间预订者信息如下:\n");
printf("\t\t==============================================\n");
printf("\t\t 姓 名 性 别 身份证号 登记时间 \n");
printf("\t\t*--------------------------------------------*\n");
printf("\t\t %6s %2s %18s %d/%d/%d\n",customer.Name,customer.Sex,customer.ID_card,customer.year,customer.month,customer.day);
printf("\t\t==============================================\n");
printf("\n确定退订该房间吗?(Y/N)\n");
while(!kbhit());
while(flag!='y'&&flag!='Y'&&flag!='n'&&flag!='N')
{
flag=getch();
flag=tolower(flag);
switch(flag)
{
case 'y':{CUSOR->theroom.Sing=EMPTY;customerout(&(CUSOR->theroom));ROOMREADY++;SAVED=0;printf("\n房间退订成功!\n");break;}
case 'n':{printf("\n放弃退订房间!\n");break;}
default:{printf("\nPress y for yes or n for no!\n");break;}
}
}
break;
}
if(CUSOR->theroom.Sing==EMPTY)
{
printf("\n退订失败:该房间目前为空房间!\n");
continue;
}
if(CUSOR->theroom.Sing==CHECKEDIN)
{
printf("\n退订失败:该房间已有房客入住,非预订房间,如需退房请选择退房登记!\n");
continue;
}
}
}
void checkin() /*开房*/
{
char roomid[6]="";
struct Client customer;
struct Rooms *HEAD=ROOM;
struct Rooms *CUSOR=HEAD;
if(CUSOR==NULL)
{
printf("\n开房失败:酒店现无房间!\n");
return;
}
customer=registercustomer();
while(1)
{
printf("\n房间号:");
scanf("%s",roomid);
cmdtolower(roomid);
if(!strcmp(roomid,"quit")) break;
HEAD=ROOM;
CUSOR=HEAD;
while(CUSOR!=NULL)
{
if(!strcmp(roomid,CUSOR->theroom.Room_ID)) break;
CUSOR=CUSOR->next;
}
if(CUSOR==NULL)
{
printf("\n开房失败:房间号不存在!\n");
continue;
}
if(CUSOR->theroom.Sing==EMPTY)
{
CUSOR->theroom.Sing=CHECKEDIN;
CUSOR->theroom.Client_list=customer;
ROOMREADY--; /*空房间减一*/
SAVED=0;
printf("\n开房成功!\n");
break;
}
if(CUSOR->theroom.Sing==BOOKED)
{
if(strcmp(CUSOR->theroom.Client_list.Name,customer.Name))
{
printf("\n开房失败:该房间已被其他顾客预订,请选择其他房间!\n");
continue;
}
else
{
CUSOR->theroom.Sing=CHECKEDIN;
CUSOR->theroom.Client_list=customer;
printf("\n开房成功!\n");
break;
}
}
if(CUSOR->theroom.Sing==CHECKEDIN)
{
printf("\n开房失败:该房间已有房客入住,请选择其他房间!\n");
continue;
}
}
}
void checkout() /*退房*/
{
char roomid[6]="";
char flag='x';
struct Client customer;
struct Rooms *HEAD=ROOM;
struct Rooms *CUSOR=HEAD;
if(CUSOR==NULL)
{
printf("\n退房失败:酒店现无房间!\n");
return;
}
if(ROOMREADY==ROOMCNT)
{
printf("\n预房失败:酒店目前尚无有客房间!\n");
return;
}
while(1)
{
printf("\n待退房间号:");
scanf("%s",roomid);
cmdtolower(roomid);
if(!strcmp(roomid,"quit")) break;
HEAD=ROOM;
CUSOR=HEAD;
while(CUSOR!=NULL)
{
if(!strcmp(roomid,CUSOR->theroom.Room_ID)) break;
CUSOR=CUSOR->next;
}
if(CUSOR==NULL)
{
printf("\n退房失败:房间号不存在!\n");
continue;
}
if(CUSOR->theroom.Sing==CHECKEDIN)
{
customer=CUSOR->theroom.Client_list;
printf("\n房间已找到,房间信息如下:\n");
printf("\t\t==============================================\n");
printf("\t\t 房间号 房间电话 房间价格 房间状态 \n");
printf("\t\t*--------------------------------------------*\n");
printf("\t\t %4s %7s %4u 已入住 \n",CUSOR->theroom.Room_ID,CUSOR->theroom.Tel,CUSOR->theroom.Price);
printf("\t\t==============================================\n");
printf("\n房客信息如下:\n");
printf("\t\t==============================================\n");
printf("\t\t 姓 名 性 别 身份证号 登记时间 \n");
printf("\t\t*--------------------------------------------*\n");
printf("\t\t %6s %2s %18s %d/%d/%d\n",customer.Name,customer.Sex,customer.ID_card,customer.year,customer.month,customer.day);
printf("\t\t==============================================\n");
printf("\n确定退房吗?(Y/N)\n");
while(!kbhit());
while(flag!='y'&&flag!='Y'&&flag!='n'&&flag!='N')
{
flag=getch();
flag=tolower(flag);
switch(flag)
{
case 'y':{
CUSOR->theroom.Sing=EMPTY;
customerout(&(CUSOR->theroom));
ROOMREADY++;
SAVED=0;
printf("\n退房成功!\n");
break;
}
case 'n':{printf("\n放弃退房!\n");break;}
default:{printf("\nPress y for yes or n for no!\n");break;}
}
}
printf("%s",CUSOR->theroom.Client_list.Name);
break;
}
if(CUSOR->theroom.Sing==EMPTY)
{
printf("\n退房失败:该房间目前为空房间!\n");
continue;
}
if(CUSOR->theroom.Sing==BOOKED)
{
printf("\n退房失败:该房间已被预订,并未入住,如需退订请选择退订登记!\n");
continue;
}
}
}
void ready() /*查看空房间*/
{
struct Rooms *HEAD=ROOM;
struct Rooms *CUSOR=HEAD;
unsigned roomready=0;
printf("\t\t\t ======空闲客房列表======\n");
printf("\t\t==============================================\n");
printf("\t\t 房间号 房间电话 房间价格 房间状态 \n");
printf("\t\t*--------------------------------------------*\n");
while(CUSOR!=NULL)
{
if(CUSOR->theroom.Sing==EMPTY)
{
printf("\t\t %4s %7s %4u 空闲 \n",CUSOR->theroom.Room_ID,CUSOR->theroom.Tel,CUSOR->theroom.Price);
printf("\t\t*--------------------------------------------*\n");
roomready++;
}
CUSOR=CUSOR->next;
}
printf("\t\t 合计: %u 间\n",roomready);
printf("\t\t==============================================\n");
}
void cquery() /*房客查询*/
{
char customername[20]="";
char customersex[6]="";
char customeridcard[20]="";
char chice[6]="";
char flag='x',flag1='x';
unsigned resultcnt=0;
struct Rooms *HEAD=ROOM;
struct Rooms *CUSOR=HEAD;
if(CUSOR==NULL)
{
printf("\n查询失败:酒店现无房客!\n");
return;
}
while(1)
{
HEAD=ROOM;
CUSOR=HEAD;
resultcnt=0;
printf("\n请选择以哪一项信息作为查询条件:\n");
printf("\t\t==============================================\n");
printf("\t\t 姓 名 性 别 身份证号 \n");
printf("\t\t*--------------------------------------------*\n");
printf("\t\t 1 2 3 \n");
printf("\t\t==============================================\n");
scanf("%s",chice);
if(!strcmp(chice,"1"))
{
printf("\n输入要查询的房客的姓名:");
scanf("%s",customername);
if(!strcmp(cmdtolower(chice),"quit"))
{
printf("\n放弃查询!\n");
return;
}
printf("\t\t\t ======房客查询结果======\n");
printf("\t\t==============================================\n");
printf("\t\t 姓 名 性 别 身份证号 登记时间 \n");
printf("\t\t*--------------------------------------------*\n");
while(CUSOR!=NULL)
{
if(!strcmp(customername,CUSOR->theroom.Client_list.Name))
{
printf("\t\t %6s %2s %18s %d/%d/%d\n",CUSOR->theroom.Client_list.Name,CUSOR->theroom.Client_list.Sex,CUSOR->theroom.Client_list.ID_card,CUSOR->theroom.Client_list.year,CUSOR->theroom.Client_list.month,CUSOR->theroom.Client_list.day);
printf("\t\t*--------------------------------------------*\n");
resultcnt++;
}
CUSOR=CUSOR->next;
}
printf("\t\t 合计: %u 个\n",resultcnt);
printf("\t\t==============================================\n");
while(flag1!='c'&&flag1!='C'&&flag1!='q'&&flag1!='Q')
{
printf("\n继续查询:C,退出:Q\n");
flushstdin();
flag1=getch();
flag1=tolower(flag1);
}
switch(flag1)
{
case 'c': {flag1='x';continue;break;}
case 'q': {flag1='x';printf("\n选择退出。\n");return;break;}
}
}
if(!strcmp(chice,"2"))
{
printf("\n输入要查询的房客的性别:");
scanf("%s",customersex);
if(!strcmp(cmdtolower(chice),"quit"))
{
printf("\n放弃查询!\n");
return;
}
printf("\t\t\t ======房客查询结果======\n");
printf("\t\t==============================================\n");
printf("\t\t 姓 名 性 别 身份证号 登记时间 \n");
printf("\t\t*--------------------------------------------*\n");
while(CUSOR!=NULL)
{
if(!strcmp(customersex,CUSOR->theroom.Client_list.Sex))
{
printf("\t\t %6s %2s %18s %d/%d/%d\n",CUSOR->theroom.Client_list.Name,CUSOR->theroom.Client_list.Sex,CUSOR->theroom.Client_list.ID_card,CUSOR->theroom.Client_list.year,CUSOR->theroom.Client_list.month,CUSOR->theroom.Client_list.day);
printf("\t\t*--------------------------------------------*\n");
resultcnt++;
}
CUSOR=CUSOR->next;
}
printf("\t\t 合计: %u 个\n",resultcnt);
printf("\t\t==============================================\n");
while(flag1!='c'&&flag1!='C'&&flag1!='q'&&flag1!='Q')
{
printf("\n继续查询:C,退出:Q\n");
flushstdin();
flag1=getch();
flag1=tolower(flag1);
}
switch(flag1)
{
case 'c': {flag1='x';continue;break;}
case 'q': {flag1='x';printf("\n选择退出。\n");return;break;}
}
}
if(!strcmp(chice,"3"))
{
printf("\n输入要查询的房客的身份证号:");
scanf("%s",customeridcard);
if(!strcmp(cmdtolower(chice),"quit"))
{
printf("\n放弃查询!\n");
return;
}
printf("\t\t\t ======房客查询结果======\n");
printf("\t\t==============================================\n");
printf("\t\t 姓 名 性 别 身份证号 登记时间 \n");
printf("\t\t*--------------------------------------------*\n");
while(CUSOR!=NULL)
{
if(!strcmp(customeridcard,CUSOR->theroom.Client_list.ID_card))
{
printf("\t\t %6s %2s %18s %d/%d/%d\n",CUSOR->theroom.Client_list.Name,CUSOR->theroom.Client_list.Sex,CUSOR->theroom.Client_list.ID_card,CUSOR->theroom.Client_list.year,CUSOR->theroom.Client_list.month,CUSOR->theroom.Client_list.day);
printf("\t\t*--------------------------------------------*\n");
resultcnt++;
}
CUSOR=CUSOR->next;
}
printf("\t\t 合计: %u 个\n",resultcnt);
printf("\t\t==============================================\n");
while(flag1!='c'&&flag1!='C'&&flag1!='q'&&flag1!='Q')
{
printf("\n继续查询:C,退出:Q\n");
flushstdin();
flag1=getch();
flag1=tolower(flag1);
}
switch(flag1)
{
case 'c': {flag1='x';continue;break;}
case 'q': {flag1='x';printf("\n选择退出。\n");return;break;}
}
}
if(!strcmp(chice,"quit"))
{
printf("\n放弃查询!\n");
return;
}
printf("\n无效选择!\n");
}
}