当前位置:文档之家› 酒店管理系统代码

酒店管理系统代码

#include <windows.h>#include <dos.h>#include<stdio.h>#include<stdlib.h>#include<time.h>//--------------------------------------------------结构定义------------------------------------------ typedef struct CheckinInformation{char name[10]; //姓名int id; //证件号int roomType; //房型int countType; //计费方式}CheckinInfo;typedef struct HotelRoom{int roomType; //房型int roomNum; //房号int checked; //入住情况int price; //房价}Room;typedef struct RoomOrder{CheckinInfo *checkinInfo; //入住信息long date; //入住时间Room * room; //房间信息}Order;typedef struct HotelInfomation{int checkinAmount; //已入住房数int singleRemainAmount; //单人房剩余房数int doubleRemainAmount; //双人房剩余房数int bigRemainAmount; //大床房剩余房数}HotelInfo;//--------------------------------枚举类型---------------------------enum {MainUI,HotelInfoUI,CheckinUI,CheckinResultUI,OrderUI,CheckOutUI,Exit};//GUI enum {Single,Double,Big};//Room Typeenum {Hour,Day};//countType//--------------------------------全局变量--------------------------int GUI = MainUI;Order* orderList[100];//订单数组Room* roomList[100];//房间数组HotelInfo * hotelInfo = NULL;//酒店房间信息//-------------------------------函数声明---------------------------- void initiallizeRoomList();void insertToOrderList(Order * order);Room* getRoomByType(int roomType);Order* getOrderByRoomNum(int roomNum);void showMainUI();void showHotelInfoUI();void showCheckinUI();void showCheckinResultUI();void showOrderUI();void showCheckOutUI();//-------------------------------Main函数---------------------------- void main() //主函数{//初始化酒店房间信息hotelInfo = (HotelInfo *)malloc(sizeof(HotelInfo));hotelInfo -> singleRemainAmount = 20;hotelInfo -> doubleRemainAmount=40;hotelInfo -> bigRemainAmount=40;hotelInfo -> checkinAmount=0;//初始化房间列表initiallizeRoomList();//界面显示while(GUI != Exit){switch(GUI){case MainUI:showMainUI();break;case HotelInfoUI:showHotelInfoUI();break;case CheckinUI:showCheckinUI();break;case CheckinResultUI:showCheckinResultUI();break;case OrderUI:showOrderUI();break;case CheckOutUI:showCheckOutUI();break;default:break;}}}//-------------------------------函数定义----------------------------void initiallizeRoomList(){//房间数组初始化,初始化的结果是让roomList的数组有100个room指针,而且设置了相应的值int i;Room*newRoom=NULL;for(i=0;i<20;i++) //单人房房间信息初始化{newRoom = ( Room* )malloc(sizeof(Room));roomList[i] = newRoom;roomList[i]->checked=0;roomList[i]->price=110;roomList[i]->roomNum=i+1;roomList[i]->roomType=Single;}for(i=20;i<60;i++) //双人房房间信息初始化{newRoom = ( Room* )malloc(sizeof(Room));roomList[i] = newRoom;roomList[i]->checked=0;roomList[i]->price=180;roomList[i]->roomNum=i+1;roomList[i]->roomType=Double;}for(i=60;i<100;i++) //大床房房间信息初始化{newRoom = ( Room* )malloc(sizeof(Room));roomList[i] = newRoom;roomList[i]->checked=0;roomList[i]->price=180;roomList[i]->roomNum=i+1;roomList[i]->roomType=Big;}}//通过所选择的房型获取空房间,获取房间后将房间信息改为已入住,并减少相应房型的剩余房间数Room* getRoomByType(int roomType){int i;switch(roomType){case Single:for(i=0;i<20;i++){if( roomList[i]->checked == 0){roomList[i]->checked=1;hotelInfo->singleRemainAmount -- ;hotelInfo->checkinAmount++;return roomList[i];}}break;case Double:for(i=20;i<60;i++){if( roomList[i]->checked == 0){roomList[i]->checked=1;hotelInfo->doubleRemainAmount -- ;hotelInfo->checkinAmount++;return roomList[i];}}break;case Big:for(i=60;i<100;i++){if( roomList[i]->checked == 0){roomList[i]->checked=1;hotelInfo->bigRemainAmount --;hotelInfo->checkinAmount++;return roomList[i];}}break;}}//将订单放入订单列表void insertToOrderList(Order * order){int i;for( i = 0;i<100;i++){if( orderList[i] ==NULL ){orderList[i] = order;break;}}}//通过房号查询订单Order* getOrderByRoomNum(int roomNum){int i;for(i=0;i<100;i++){if( orderList[i]->room->roomNum == roomNum){return orderList[i];}}void showMainUI(){//显示主界面,并接受输入int chooseNum;system("cls");printf("\n\n==========================酒店房间登记与计费管理管理系统=======================\t\n\n\n");printf("*\t\t\t\t1. 入住登记\t\t\t\t*\n");printf("*\t\t\t\t2. 查询入住情况\t\t\t*\n");printf("*\t\t\t\t3. 查询当前费用\t\t\t*\n");printf("*\t\t\t\t4. 结账退房\t\t\t\t*\n");printf("*\t\t\t\t5. 退出程序\t\t\t\t*\n\n\n");printf("\n\n==========================酒店房间登记与计费管理管理系统=======================\t\n\n\n");printf("请输入相应编号进入菜单\t");//接受输入scanf("%d",&chooseNum);switch(chooseNum){case 1:GUI = HotelInfoUI;break;case 2:GUI = HotelInfoUI;break;case 3:GUI = OrderUI;break;case 4:GUI = OrderUI;break;case 5:Sleep(3000);GUI = Exit;break;default:break;}void showHotelInfoUI(){int chooseNum;system("cls");printf("\n\n=========================酒店入住情况查询菜单=======================\t\n\n\n\n");printf("*\t\t\t入住房间数: %d\t\t\t\t*\n", hotelInfo->checkinAmount);printf("*\t\t\t剩余房间数: \t");printf("单人房:%d\t\t*\n",hotelInfo->singleRemainAmount);printf("*\t\t\t\t\t双人房:%d\t\t*\n",hotelInfo->doubleRemainAmount);printf("*\t\t\t\t\t大床房:%d\t\t*\n\n",hotelInfo->bigRemainAmount);printf("\n\n=========================酒店入住情况查询菜单=======================\t\n\n\n");printf("按0 :返回\n");printf("按1 : 登记入住\n");scanf("%d",&chooseNum);switch(chooseNum){case 0:GUI = MainUI;break;case 1:GUI = CheckinUI;break;default:GUI = HotelInfoUI;break;}}void showCheckinUI(){Order * newOrder;Room* newRoom = NULL;//填写一个新的入住信息CheckinInfo * newCheckinInfo = NULL;int roomTypeNum;int countTypeNum;time_t timep;system("cls");printf("\n\n===========================酒店入住登记菜单=========================\t\n\n\n");newCheckinInfo = ( CheckinInfo * )malloc(sizeof(CheckinInfo));printf("*\t\t请输入姓名:");scanf("%s", &(newCheckinInfo->name) );printf("*\t\t请输入证件号:");scanf("%d", &(newCheckinInfo->id) );printf("*\t\t请选择入住房型:\n");printf("\t\t\t1.单人房\n\t\t\t2.双人房\n\t\t\t3.大床房\n");scanf("%d",&(roomTypeNum));switch(roomTypeNum) //通过输入的数字对应房型{case 1:newCheckinInfo->roomType = Single;break;case 2:newCheckinInfo->roomType = Double;break;case 3:newCheckinInfo->roomType = Big;break;default:newCheckinInfo->roomType = Single;break;}printf("*\t\t请选择计费方式:\n");printf("\t\t\t1.按小时计费; \n\t\t\t2.按天数计费\n"); //通过输入的数字对应计费方式scanf("%d",&countTypeNum);switch(countTypeNum){case 1:newCheckinInfo->countType = Hour;break;case 2:newCheckinInfo->countType = Day;break;}printf("\n\n===========================酒店入住登记菜单=========================\t\n\n\n");//生成一个新的订单newOrder = ( Order* )malloc(sizeof(Order));newOrder -> checkinInfo = newCheckinInfo;newOrder -> date = time(0);switch(newCheckinInfo->roomType) //通过房型获取房间{case Single:newRoom = getRoomByType(Single);break;case Double:newRoom=getRoomByType(Double);break;case Big :newRoom=getRoomByType(Big);break;}newOrder->room = newRoom;insertToOrderList(newOrder);printf("房间号为:%d\n",newOrder->room->roomNum);GUI = CheckinResultUI;}void showCheckinResultUI(){int chooseNum;printf("\n\n=========================酒店入住登记确认菜单=======================\t\n\n\n");printf("\t\t\t************\t\t\t\t\n");printf("\t\t\t* 登记成功*\t\t\t\t\n");printf("\t\t\t************\t\t\t\t\n\n");printf("\n\n=========================酒店入住登记确认菜单=======================\t\n\n\n");printf("按0 :返回\n");scanf("%d",&chooseNum);switch(chooseNum){case 0:GUI = MainUI;break;default:GUI = CheckinResultUI;break;}}void showOrderUI(){int roomNum;int chooseNum;int amount;Order * theOrder = NULL;system("cls");printf("\n\n=========================酒店房间信息查询菜单=======================\t\n\n\n");printf("请输入房间号:");scanf("%d",&roomNum);if (roomNum<0 || roomNum>100){printf("\n 输入有误请重新输入") ;GUI = OrderUI;}else{theOrder = getOrderByRoomNum(roomNum);printf("房型:");switch(theOrder->room->roomType){case Single:printf("单人房\n");break;case Double:printf("双人房\n");break;case Big:printf("大床房\n");break;}printf("计费方式:");switch(theOrder->checkinInfo->countType ){case Hour:printf("小时计费\n");amount = (time(0) - theOrder->date) / 3600 +1;printf("已入住时间:%d小时\n",amount);break;case Day:printf("天计费\n");amount = (time(0) - theOrder->date) / (3600*24) +1;printf("已入住时间:%d天\n",amount);break;}printf("房价:%d\n",theOrder->room->price);printf("应支付:%d\n\n",amount * theOrder->room->price);printf("\n\n=========================酒店房间信息查询菜单=======================\t\n\n\n");printf("按0:返回\n");printf("按1:结账退房\n");scanf("%d",&chooseNum);switch(chooseNum){case 0:GUI = MainUI;break;case 1:GUI = CheckOutUI;break;default:break;}}}void showCheckOutUI(){int chooseNum;printf("\n\n=========================酒店结账退房确认菜单=======================\t\n\n\n");printf("\t\t\t\t************\t\t\t\t\n");printf("\t\t\t\t* 结账成功*\t\t\t\t\n");printf("\t\t\t\t************\t\t\t\t\n\n");printf("\n\n=========================酒店结账退房确认菜单=======================\t\n\n\n");printf("按0:返回");scanf("%d",&chooseNum);switch(chooseNum) {case 0:GUI = MainUI;break;default:GUI = CheckOutUI;break;}}。

相关主题