📄 管理系统.txt
字号:
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<io.h> /*包含低级I/O子程序的结构和说明*/
#include<direct.h> /*包含文件*/
/*基本类型*/
#include<Type.h>
/*客房类型*/
#define SINGLE_ROOM (BYTE)1 /*单人间*/
#define DOUBLE_ROOM (BYTE)2 /*双人间*/
#define TRIANGULAR_ROOM (BYTE)3 /*双人间*/
/*客房状态*/
#define IDLE_STATUS (BYTE)0 /*空闲*/
#define BUSY_STATUS (BYTE)1 /*使用中*/
/*一间客房最多容纳顾客人数*/
#define MAAX_CUSTOMER_NUM (BYTE)3
typedef char CUSTOMERID[31];
/*顾客(内存结构)*/
typedef struct _customer
{
char name[31]; /*名字*/
CUSTOMER id; /*有效证件(身份证)*/
char date[9]; /*日期*/
WORD days; /*天数*/
struct _customer *next;
}
CUSTOMER;
/*顾客(存储结构)*/
typedef struct _customersto
{
char name[31]; /*名字*/
CUSTOMERRID id; /*有效证件(身份证)*/
char date[9]; /*日期*/
WORD days; /*天数*/
}
CUSTOMERSTO;
typedef char ROOMNO[11];
/*客房(内存结构)*/
typedef struct _room
{
ROOMNO no; /*编号*/
BYTE type; /*类型*/
BYTE status; /*状态*/
CUSTOMER *pcustomer[MAX_CUSTOMER_NUM]; /*顾客*/
struct_room *next;
}
ROOM;
/*客房(内存结构)*/
typedef struct _roomsto
{
ROOMNO no; /*编号*/
BYTE type; /*类型*/
BYTE status; /*状态*/
CUSTOMERID cid[MAX_CUSTOMER_NUM]; /*顾客*/
}ROOMSTO;
/*调试*/
#define DEBUG 1
/*输入提示符*/
#define INPUT_PROMPT "输入〉"
/*日志目录*/
#define LOG_DIR "./log"
/*日志文件*/
#define LOG_FILE "./log/hotle.log"
/*数据目录*/
#define DATA_DIR "./data"
/*客房数据文件*/
#define ROOM_FILE "./data/room.dat"
/*旅客数据文件*/
#define CUSTOMER_FILE "./data/customer.dat"
/*8位整数*/
typedef unsigned char BYTE;
typedef unsigned char Uchar;
typedef signed char char;
/*16位整数*/
typedef unsigned short WORD;
typedef unsigned char UINT16;
typedef signed char INT16;
/*32位整数*/
typedef unsigned short WORD;
typedef unsigned char Ushort int;
typedef signed char short int;
/*浮点数*/
typedef float FLOAT;
typedef double DOUBLE;
/*布尔型和值*/
typedef unsigned char BOOL;
#define TRUE (unsigned char)1
#define FALESE (unsigned char)0
/*指针*/
typedef char* PSTRING;
typedef unsigned char* UPSTRING;
typedef void* PVOID;
/*其他*/
typedef void
#define SUCCESS (int)0
#define ERROR (int)-1
#if defined(_cplusplus) || defined(c_plusplus)
extern <C>
{
#endif
#include<Hotel.h>
extern CUSTOMER *AllocACustomer();
exter CUSTOMER *GetCustomerById(char *id);
exter short int LinkCustomer(CUSTOMER *pcustomer);
exter ROOM *AllocARoom();
exter short int LinkRoom(ROOM *proom);
/*读取客户信息*/
short int ReadCustomer();
/*读取客房信息*/
short int ReadRoom();
/*初始化*/
VOID Init();
/*
**读取客户信息
*/
short int ReadCustomer()
{
short int count=0;
CUSTOMER *pcustomer=NULL;
FILE *pfile=NULL;
CUSTOMERSTO cstore;
if(DEBUG)
{
printf("加载客户数据……\n");
}
if(NULL==(pfile=fopen(CUSTOMER_FILE,"rb")))
{
return count;
}
while(fread(&castor,sizeof(castore),1,pfile))
{
if(NULL==(pcustomer=AllocACustomer()))
{
break;
}
strcpy(pcustomer->name,cstore.name); /*名字*/
strcpy(pcustomer->id,cstore.id); /*有效证件(身份证)*/
strcpy(pcustomer->date,cstore.date); /*日期*/
pcustomer->days=cstore.days; /*天数*/
if(DEBUG)
{
printf("顾客[%d]\n",count);
printf("名字:%s\n",pcustomer->name);
printf("有效证件(身份证):%s\n",pcustomer->id);
printf("日期:%s\n",pcustomer->date);
printf("天数:%d\n\n",pcustomer->days);
}
LinkCustomer(pcustomer);
coint++;
}
fclose(pfile);
return count;
}
/*
**读取客房信息
*/
short int ReadRoom()
{
short int count=0;
ROOM *proom=NULL;
FILE *prile=NULL;
ROOMSTO rstore;
short int i;
if(DEBUG)
{
printf("加载客房信息……\n");
}
if(NULL==(pfile=fopen(ROOM_FILE,"rb")))
{
return count;
}
while(fread(&rstore,sizeof(rstore),1,pfile)
{
proom=AllocARoom();
if(NULL==proom)
{
break;
}
strcpy(proom->no,rstore.no); /*编号*/
proom->type=rstore.type; /*类型*/
proom->status=rstore.status; /*状态*/
for(i=0;i<proom->type;i++) /*顾客*/
{
proom->pcustomer[i]=GetCustomerById(rstore.cid[i]);
}
if(DEBUG)
{
printf("客房[%d]\n",count);
printf("编号:%s\n",proom->no);
printf("类型:%d\n",proom->type);
printf("顾客:",count);
for(i=0;i<proom->type;i++)
{
if(NULL!=proom->pcustomer[i]->name);
{
printf("%s/",proom->pcustomer[i]->name);
}
}
printf("\n\n");
}
LinkRoom(proom);
count++;
}
fclose(pfile);
return count;
}
#if defined(_cplusplus)||defined(c_plusplus)
}
#endif
#if defined(_cplusplus) || defined(c_plusplus)
extern <C>
{
#endif
#include <Hotel.h>
/*初始化*/
extern VOID Init();
/*登记*/
extern short int CheckIn();
/*退房*/
extern short int CheckOut();
/*配置*/
extern short int Config();
/*保存*/
extern short int Save();
/*
**主菜单
*/
static VOID MainMenu()
{
BYTE choice;
BOOL change=FALSE;
BOOL done=FALSE;
while(!done)
{
printf(" || 欢 迎 进 入 ||\n");
printf(" ||**************************||\n");
printf(" ||---------主 菜 单---------||\n");
printf(" || 1 . 登 记 ||\n");
printf(" || 2 . 退 房 ||\n");
printf(" || 3 . 配 置 ||\n");
printf(" || 4 . 保 存 ||\n");
printf(" || 5 . 退 出 ||\n");
printf(" ||---------金碧旅店---------||\n");
printf(" ||**************************||\n");
printf(" || 谢 谢 使 用 ||\n");
printf(INPUT_PROMPT);
choice=getch();
if(DEBUG)
{
printf("choice:(%c)\n",choice);
}
if('1'<=choice&&choice<='3')
{
change=TRUE;
}
switch(choic)
{
case '1':
CheckIn();
break;
case '2':
CheckOut();
break;
case '3':
Config();
break;
case '4':
if(change)
{
Save();
change=FALSE;
}
break;
case '5':
if(change)
{
printf("修改尚未保存,真的要退出吗?(Y/N)>");
choice=getch();
if('Y'==choice&&'y'==choice)
{
done=TURE;
}
printf("\n");
}
else
{
done=TRUE;
}
default:
printf("请选择和功能相对应的数字1-5\n");
break;
}
}
}
VOID main(int argc,char **args)
{
/*初始化*/
Init();
/*主菜单*/
MainMenu();
}
#if defined(_cplusplus) || defined(c_plusplus)
}
#endif
#if defined(_cplusplus)||defined(c_plusplus)
extern <C>
{
#endif
#include<Hotel.h>
extern CUSTOMER *AllocACustomer();
extern short int LinkCustomer(CUSTOMER *pcustomer);
extern short int ListCustomer();
extern ROOM *roomLink;
extern char *RoomType(char type);
extern ROOM *GetRoomByNo(ROOMNO no);
/*
**顾客登记
*/
short int Register()
{
BYTE choice,type;
char line[256];
short int count,i;
CUSTOMER *pcustomer=NULL;
ROOM *proom=NULL;
ROOMNO no;
while(TRUE)
{
printf("\n请选择客房类型(1 单人间 2 双人间 3 三人间 4 返回)>");
choice=getch();
switch(choice)
{
case '1':
type=SINGLE_ROOM;
break;
case '2':
type=DOUBLE_ROOM;
break;
case '3':
type=TRIANGULAR_ROOM;
break;
default:
return 0;
}
count=0;
proom=roomLink;
while(NULL!=proom)
{
if(proom->type==type&&proom->status==IDLE_STATUS")
{
if(0==count)
{
printf("\n可选择客房:");
}
printf("%s",proom->no);
count++;
}
proom=proom->next;
}
if(0==count)
{
printf("\n%s客已满",RoomType(type));
continue;
}
printf("\n输入客房编号>");
gets(no);
proom=GetRoomByNo(no);
if(NULL==proom||IDLE_STATUS!=proom->status)
{
continue;
}
for(i=0;i<proom->type;i++)
{
if(i>0)
{
printf("登记另一个顾客(Y/N)>");
choice=getch();
if('Y'!=choice&&'y'!==choice)
{
break;
}
printf("\n");
}
pcustomer=AllocACustomer();
if(NULL==pcustomer)
{
return ERROR;
}
printf("输入顾客名字>");
gets(pcustomer->name);
printf("输入顾客证件>");
gets(pcustomer->id);
printf("输入日期>");
gets(pcustomer->date);
printf("输入天数>");
gets(line);
pcustomer->days=atoi(line);
/*加入链表*/
LinkCustomer(pcustomer);
/*指定客户节点*/
proom->pcustomer[i]=pcustomer;
}
proom->status=BUSY_STATUS;
}
return SUCCESS;
}
short int CheckIn()
{
BYTE choice;
bool done=FALSE;
while(!done)
{
printf(" \n");
printf(" ||**************************||\n");
printf(" ||----------登 记---------||\n");
printf(" || 1 . 顾客登记 ||\n");
printf(" || 2 . 顾客列表 ||\n");
printf(" || 3 . 回主菜单 ||\n");
printf(" ||----------金J B碧---------||\n");
printf(" ||**************************||\n");
printf(INPUT_PROMPT);
choice=getch();
if(DEBUG)
{
printf("choice:(%c)\n",choice);
}
switch(choice)
{
case '1':
Register();
break;
case '2':
ListCustomer();
break;
default:
done=TRUE;
break;
}
}
return SUCCESS;
}
#if defined(_cplusplus)||defined(c_plusplus)
}
#endif
#if defined(_cplusplus)||defined(c_plusplus)
extern<C>
{
#endif
#include<Hotel.h>
extern CUSTOMER *customerlink;
extern ROOM *GetRoomByCustomer(CUSTOMER *pcustomer);
extern CUSTOMER *GetRoomById(CUSTOMERID id);
extern short int DeleteCustomerById(CUSTOMER id);
/*
**顾客退房
*/
short int Check()
{
CUSTOMERID id;
CUSTOMER *pcustomer=NULL;
ROOM *proom=NULL;
short int i,count;
BYTE choice;
while(NULL!=customerLink)
{
print("\有效证件(身份证)>");
gets(id);
pcustomer=GetCustomerBYId(id);
if(NULL!=pcustomer)
{
proom=GetRoomByCustomer(pcustomer);
if(NULL!=proom)
{
printf("顾客(%s)退出房间(%s)。\n",pcustomer->name,proom->no);
count=0;
for(i=0;i<proom->type;i++)
{
if(proom->pcustomer[i]==pcustomer)
{
proom->pcustomer[i]=NULL;
}
else if(NULL!=proom->pcustomer[i])
{
count++;
}
}
}
DeleteCustomerById(id);
}
else
{
printf("顾客(%s)不存在。",id);
}
printf("\n继续(Y\N)>");
choice=getch();
if('Y'!=choice&&'y'!=choice)
{
break;
}
printf("\n");
}
return SUCCESS;
}
/*
**显示客户
*/
short int LinkCuatomer()
{
ROOM *proom=NULL;
CUSTOMER *pcustomer=customerLInk;
if(NULL==customer)
{
printf("无客户。\n");
}
while(NULL!=pcustomer)
{
printf("\n顾客:%s",pcustomer->name);
printf("\n证件:%s",pcustomer->id);
proom=GetRoomCustomer(pcustomer);
if(NULL!=proom)
{
print("\n客房:%s",proom->no);
}
printf("\n日期:%s",pcustomer->date);
printf("\n天数:%s",pcustomer->days);
pcustomer=pcustomer->next;
}
return SUCCESS;
}
/*
**退房
*/
short int CheckOut()
{
BYTE choice;
BOOL done=FAlES;
while(!done)
{
printf(" \n");
printf(" ||**************************||\n");
printf(" ||----------退 房---------||\n");
printf(" || 1 . 顾客退房 ||\n");
printf(" || 2 . 顾客列表 ||\n");
printf(" || 3 . 回主菜单 ||\n");
printf(" ||----------金J B碧---------||\n");
printf(" ||**************************||\n");
printf(INPUT_PROMPT);
if(DEBUG)
{
printf("choice:(%c)\n",choice);
}
switch(choice)
{
case '1':
Check();
break;
case '2':
ListCustomer();
break;
default:
done=TRUE;
break;
}
}
return SUCCESS;
}
#if defined(_cplusplus)||defined(c_plusplus)
}
#endif
#if defined(_cplusplus)||(c_plusplus)
extern<c>
{
#endif
#include<Hotel.h>
exter CUSTOMER *customerLink;
exter ROOM *roomLink;
extern BOOL RoomExists(char *no);
extern short int LinkRoom(ROOM *proom);
extern short int DeleteRoomNode(char *no);
extern ROOM *AllocARoom();
extern char *RoomType(char type);
extern char *RoomStatus(ROOM *proom);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -