博客 / 詳情

返回

C++程序設計:酒店客房管理系統

一、功能描述

本項目為“酒店客房管理系統”,實現了對酒店的客房信息進行管理,主要功能包括:

  1. 酒店初始化

    (1) 初始化管理員賬號密碼

    (2) 初始化操作員賬號密碼

    (3) 初始化酒店客房信息

  2. 管理員管理

    (1) 管理員登錄

    (2) 查看、增加、刪除、修改操作員信息

    (3) 操作員信息寫入文件

    (4) 查看、修改酒店客房信息

    (5) 酒店客房信息寫入文件

  3. 操作員管理

    (1) 查看客房信息

    (2) 客房的預訂

    (3) 客房的入住

    (4) 客房的退房

    (5) 預訂查詢(根據房號和姓名查詢預訂信息)

    (6) 客房查詢(根據房號查詢房間信息)

    (7) 住客查詢(根據姓名查詢住客信息)

    (8) 操作員工作日誌寫入文件

二、設計與實現

1. 模塊結構圖及各模塊的功能

模塊結構圖如下:

模塊圖.png

本酒店客房管理系統有兩個模塊:管理員模塊和操作員模塊。

管理員模塊的功能有:

  • 管理員登錄:根據輸入賬號密碼登錄進入管理員權限
  • 操作員管理

    • 查看操作員信息
    • 增加操作員信息
    • 刪除操作員信息
    • 修改操作員信息
  • 酒店客房管理

    • 查看酒店客房信息
    • 修改酒店客房信息

操作員模塊的功能有:

  • 操作員登錄:根據輸入賬號密碼登錄進入操作員權限
  • 查看客房信息
  • 客房的預訂
  • 客房的入住
  • 客房的退房
  • 預訂查詢:根據房號和姓名查詢預訂信息
  • 客房查詢:根據房號查詢房間信息
  • 住客查詢:根據姓名查詢住客信息

2. 數據類型的設計和説明

函數調用關係

main.png

Room類

Room類的數據類型如下:

Room.png

​ 在本項目的設計中,Room是酒店客房的抽象,而Room數組是酒店的抽象。

​ 友元函數RoomInit:進行酒店房間初始化。本項目初始化了20間客房的類型和價格,並將酒店客房信息保存在“酒店房間信息.xls”文件中。

Operator類

Operator.png

​ 在本項目中,Operator是酒店操作員的抽象,並用一個Operator數組保存操作員信息。

​ 友元函數OperatorInit():進行操作員信息的初始化。本項目初始化了10位操作員的賬號和密碼,並將酒店客房信息保存在“操作員賬户信息.txt”文件中。

​ 友元函數OperatorLogin():登錄操作員賬號。該函數傳入Operator數組並返回登錄操作員在數組的第幾個元素。

​ 成員函數WriteRoomInformation(Room*):將Room數組中的信息寫入到“酒店房間信息.xls”文件中。該函數是一個輔助函數,當Room數組的信息進行修改時,將調用該函數修改文件相應內容。

​ 實現操作員相應功能的成員函數如下:

  • ViewRoomInformation(Room*):查看酒店客房的基本信息。該信息不包括住客的基本信息。
  • ReserveRoom(Room*):預訂客房。該函數打印空閒房間讓用户選擇、並輸入用户的姓名、身份證號、聯繫方式等基本信息。
  • CheckIn(Room*):入住房間。該函數先詢問客户是否預訂房間,若預訂需對比信息才能入住,若未預訂則打印空閒房間並輸入個人信息實現入住。
  • CheckOut(Room*):住客退房。該函數輸入退房的房號並比對住客信息,如一致方可退房、將該房間的信息置空。
  • RoomQuery(Room*):客房查詢。輸入查詢房號可打印房間信息。
  • BookQuery(Room*):預訂查詢。輸入預訂房號和姓名可查詢預訂信息。
  • GuestQuery(Room*):住客查詢。輸入客户姓名可查詢客户信息。
  • OperatorQuit():操作員退出登錄。返回主登錄菜單或退出程序時將調用該函數。

​ 以上操作員的所有操作均會保存在“操作員工作日誌.xls”文件中。工作日誌的時間由當前系統時間獲得。

Administrator類

Administrator.png

​ 在本項目中,Administrator是酒店管理員的抽象。

​ 構造函數Administrator():初始化管理員賬號和密碼。在本項目中,管理員賬號和密碼被初始化後不可在程序中進行修改。

​ 友元函數OperatorLogin():登錄管理員賬號。該函數比對輸入賬號密碼與管理員賬號密碼是否一致。

​ 成員函數WriteOperatorInformation(Operator*):將Operator數組中的信息寫入到“操作員賬户信息.txt”文件中。該函數是一個輔助函數,當Operator數組的信息進行修改時,將調用該函數修改文件相應內容。

​ 實現管理員相應功能的成員函數如下:

  • ViewOperatorInformation(Operator*):查看所有操作員的賬號、密碼。
  • AddOperatorInformation(Operator*):增加操作員信息。
  • DeleteOperatorInformation(Operator*):刪除操作員信息。
  • ModifyOperatorInformation(Operator*):修改操作員信息。
  • ViewRoomInformation(Room*):查看酒店所有客房的類型與價格。
  • ModifyRoomInformation(Room*):修改酒店客房數量、類型和價格。修改後將酒店客房信息寫入“酒店房間信息.xls”文件中。

3. 關鍵功能的實現

主函數

​ main函數流程圖如下:

流程圖.png

​ 主函數中共有3個菜單界面:登錄菜單界面、管理員菜單界面和操作員菜單界面。

​ 登錄菜單界面如下:

登錄界面.png

​ 管理員菜單界面如下:

管理員界面.png

​ 操作員菜單界面如下:

操作員界面.png

修改操作員信息

​ 修改操作員信息的功能通過Administrator::ModifyOperatorInformation函數實現。

​ 流程圖如下:

修改操作員信息.png

​ 實現源代碼如下:

void Administrator::ModifyOperatorInformation(Operator* operators)
{
    ViewOperatorInformation(operators);
    int choose;
    string UserName_,Password_;
    cout<<"\t\t#請選擇要修改的操作員信息的序號: ";
    cin>>choose;
    int num = choose;
    for(int x=0;x<=choose;x++){
        if(operators[x].UserName==""){
            num++;
        }
    }
    if(operators[num-1].UserName==""){
        cout<<"\t\t#修改失敗!該操作員不存在!"<<endl;
        system("pause");
        return;
    }
    cout<<"\t\t#請輸入修改操作員賬號: ";
    cin>>UserName_; operators[num-1].UserName=UserName_;
    cout<<"\t\t#請輸入修改操作員密碼: ";
    cin>>Password_; operators[num-1].Password=Password_;
    WriteOperatorInformation(operators);
}

​ 測試界面如下:

修改操作員信息測試1.png

修改操作員信息測試2.png

修改酒店客房信息

​ 修改酒店客房信息的功能通過Administrator::ModifyRoomInformation函數實現。

​ 流程圖如下:

修改酒店客房信息.png

​ 實現源代碼如下:

void Administrator::ModifyRoomInformation(Room* room)
{
    int StandardRoomNum, StandardRoomPrice;
    int DoubleRoomNum, DoubleRoomPrice;
    int SuiteRoomNum, SuiteRoomPrice;
    cout<<"\t\t#由於本酒店客房有限,請確保輸入房間總數≤20。"<<endl<<endl;
    cout<<"\t\t#請輸入標間個數: "; cin>>StandardRoomNum;
    cout<<"\t\t#請輸入標間價格: "; cin>>StandardRoomPrice;
    cout<<endl;
    cout<<"\t\t#請輸入雙人間個數: "; cin>>DoubleRoomNum;
    cout<<"\t\t#請輸入雙人間價格: "; cin>>DoubleRoomPrice;
    cout<<endl;
    cout<<"\t\t#請輸入套房個數: "; cin>>SuiteRoomNum;
    cout<<"\t\t#請輸入套房價格: "; cin>>SuiteRoomPrice;
    cout<<endl;
    if(StandardRoomNum+DoubleRoomNum+SuiteRoomNum>20){
        cout<<"\t\t#修改失敗!您輸入的房間個數超出本酒店的房間上限!請保證房間總數≤20!"<<endl;
        system("pause");
        return;
    }
    int i[3]={1,0,1},k;
    for(k=0; k<20; k++)
    {
        room[k].RoomNum = 0;
        room[k].RoomType = "NULL";
        room[k].RoomPrice = 0;
        room[k].IsBooked = false;
        room[k].IsChecked = false;

        room[k].GuestName = "NULL";
        room[k].GuestID = "NULL";
        room[k].GuestTel = "NULL";
        room[k].CheckInTime = "NULL";
        room[k].BookTime = "NULL";
    }
    for(k=0; k<(StandardRoomNum+DoubleRoomNum+SuiteRoomNum); k++)
    {
        room[k].RoomNum=i[0]*100+i[1]*10+i[2];
        switch(i[0])
        {
        case 1:{room[k].RoomPrice=StandardRoomPrice; room[k].RoomType="標間";break;}
        case 2:{room[k].RoomPrice=DoubleRoomPrice; room[k].RoomType="雙人間";break;}
        case 3:{room[k].RoomPrice=SuiteRoomPrice; room[k].RoomType="套房";break;}
        }
        if( k==(StandardRoomNum-1) )
            i[0]++,i[2]=0;
        if( k==(DoubleRoomNum+StandardRoomNum-1) )
            i[0]++,i[2]=0;
        i[2]++;
    }
    fstream  read("酒店房間信息.xls",ios::out);
    read<<"房間號\t類型\t價格\t是否預訂\t是否入住\t姓名\t身份證號\t聯繫方式\t預訂時間\t入住時間"<<endl;
    for(int x=0;x<StandardRoomNum+DoubleRoomNum+SuiteRoomNum;x++)
    {
        read<<room[x].RoomNum<<"\t"<<room[x].RoomType<<"\t"<<room[x].RoomPrice<<"\t"<<room[x].IsBooked<<"\t"<<room[x].IsChecked<<"\t"<<room[x].GuestName
            <<"\t"<<room[x].GuestID<<"\t"<<room[x].GuestTel<<"\t"<<room[x].BookTime<<"\t"<<room[x].CheckInTime<<endl;
    }
    read.close();
    cout<<"\t\t#修改成功!"<<endl;
    system("pause");
    return;
}

​ 測試界面如下:

修改酒店客房信息測試1.png

修改酒店客房信息測試2.png

酒店客房預訂

​ 酒店客房預訂的功能通過Operator::ReserveRoom函數實現。

​ 流程圖如下:

酒店客房預訂.png

​ 實現源代碼如下:

void Operator::ReserveRoom(Room* room)
{
    int RoomNum_, x;
    cout<<"\t\t可預訂房間如下: "<<endl;
    cout<<"\t    ###########################"<<endl;
    cout<<"\t\t房間號\t類型\t價格"<<endl;
    for(x=0;x<20;x++){
        if(room[x].RoomNum!=0 && room[x].IsBooked==false && room[x].IsChecked==false){
            cout<<"\t\t"<<room[x].RoomNum<<"\t"<<room[x].RoomType<<"\t"<<room[x].RoomPrice<<endl;
        }
    }
    cout<<"\t    ###########################"<<endl;
    cout<<"\t\t#請選擇要預訂房間: "; cin>>RoomNum_;
    for(x=0;x<20;x++){
        if(room[x].RoomNum==RoomNum_){
           if(room[x].IsBooked==false && room[x].IsChecked==false) break;
           else {
            cout<<"\t\t#預訂失敗!您選擇的房間已被預訂!"<<endl;
            system("pause");
            return;
           }
        }
        if(x==19){
            cout<<"\t\t#預訂失敗!您選擇的房間已被預訂!"<<endl;
            system("pause");
            return;
        }
    }
    cout<<"\t\t#請輸入您的個人信息: "<<endl;
    cout<<"\t\t#姓名: "; cin>>room[x].GuestName;
    cout<<"\t\t#身份證號: "; cin>>room[x].GuestID;
    cout<<"\t\t#聯繫方式: "; cin>>room[x].GuestTel;
    time_t BookTime_;
    time(&BookTime_);
    room[x].BookTime = ctime(&BookTime_);
    room[x].BookTime = room[x].BookTime.substr(0, room[x].BookTime.length() - 1);
    room[x].IsBooked = true;

    fstream  file("操作員工作日誌.xls",ios::app);
    file<<UserName<<"\t"<<room[x].BookTime<<"\t預訂房間\t"<<room[x].GuestName<<"\t"<<room[x].RoomNum<<endl;
    file.close();
    WriteRoomInformation(room);

    system("cls");
    cout<<"\t\t#預訂成功!以下是您的預訂信息: "<<endl;
    cout<<"\t\t#################################################"<<endl;
    cout<<"\t\t#\t\t@曾氏酒店客房管理系統@"<<endl;
    cout<<"\t\t#"<<endl;
    cout<<"\t\t#\t姓    名: "<<room[x].GuestName<<endl;
    cout<<"\t\t#\t身份證號: "<<room[x].GuestID<<endl;
    cout<<"\t\t#\t聯繫方式: "<<room[x].GuestTel<<endl;
    cout<<"\t\t#\t預訂房號: "<<room[x].RoomNum<<endl;
    cout<<"\t\t#\t預訂時間: "<<room[x].BookTime<<endl;
    cout<<"\t\t#"<<endl;
    cout<<"\t\t#################################################"<<endl;
    system("pause");
}

​ 測試界面如下:

酒店客房預訂測試1.png

酒店客房預訂測試2.png

酒店客房入住

​ 酒店客房入住的功能通過Operator::CheckIn函數實現。

​ 流程圖如下:

酒店客房入住.png

​ 實現源代碼如下:

void Operator::CheckIn(Room* room)
{
    char choose;
    int RoomNum_, x;
    string GuestName_, GuestID_;
    cout<<"\t\t#您是否已預訂了房間?(Y/N): ";
    cin>>choose;
    if(choose=='N'||choose=='n')
    {
        cout<<"\t\t#可入住房間如下: "<<endl;
        cout<<"\t    ###########################"<<endl;
        cout<<"\t\t房間號\t類型\t價格"<<endl;
        for(int x=0;x<20;x++){
            if(room[x].RoomNum!=0 && room[x].IsBooked==false && room[x].IsChecked==false){
                cout<<"\t\t"<<room[x].RoomNum<<"\t"<<room[x].RoomType<<"\t"<<room[x].RoomPrice<<endl;
            }
        }
        cout<<"\t    ###########################"<<endl;
        cout<<"\t\t#請選擇要入住房間: "; cin>>RoomNum_;
        int x;
        for(x=0;x<20;x++){
            if(room[x].RoomNum==RoomNum_){
               if(room[x].IsBooked==false && room[x].IsChecked==false) break;
               else {
                cout<<"\t\t#入住失敗!您選擇的房間已被預訂!"<<endl;
                system("pause");
                return;
               }
            }
            if(x==19){
                cout<<"\t\t#入住失敗!您選擇的房間已被預訂!"<<endl;
                system("pause");
                return;
            }
        }
        cout<<"\t\t#請輸入您的個人信息: "<<endl;
        cout<<"\t\t#姓名: "; cin>>room[x].GuestName;
        cout<<"\t\t#身份證號: "; cin>>room[x].GuestID;
        cout<<"\t\t#聯繫方式: "; cin>>room[x].GuestTel;
        time_t CheckTime_;
        time(&CheckTime_);
        room[x].CheckInTime = ctime(&CheckTime_);
        room[x].CheckInTime = room[x].CheckInTime.substr(0, room[x].CheckInTime.length() - 1);
        room[x].IsChecked = true;

        fstream  file("操作員工作日誌.xls",ios::app);
        file<<UserName<<"\t"<<room[x].CheckInTime<<"\t入住房間\t"<<room[x].GuestName<<"\t"<<room[x].RoomNum<<endl;
        file.close();
        WriteRoomInformation(room);

        system("cls");
        cout<<"\t\t#入住成功!以下是您的入住信息: "<<endl;
        cout<<"\t\t#################################################"<<endl;
        cout<<"\t\t#\t\t@曾氏酒店客房管理系統@"<<endl;
        cout<<"\t\t#"<<endl;
        cout<<"\t\t#\t姓    名: "<<room[x].GuestName<<endl;
        cout<<"\t\t#\t身份證號: "<<room[x].GuestID<<endl;
        cout<<"\t\t#\t聯繫方式: "<<room[x].GuestTel<<endl;
        cout<<"\t\t#\t入住房號: "<<room[x].RoomNum<<endl;
        cout<<"\t\t#\t入住時間: "<<room[x].CheckInTime<<endl;
        cout<<"\t\t#"<<endl;
        cout<<"\t\t#################################################"<<endl;
        system("pause");
    }
    else if(choose=='Y'||choose=='y')
    {
        cout<<"\t\t#請輸入您預訂的房號: "; cin>>RoomNum_;
        for(x=0;x<20;x++){
            if(room[x].RoomNum==RoomNum_){
               if(room[x].IsBooked==false){
                cout<<"\t\t#入住失敗!您選擇的房間未被預訂!"<<endl;
                system("pause");
                return;
               }
               else if(room[x].IsChecked==true){
                cout<<"\t\t#入住失敗!您選擇的房間已入住!"<<endl;
                system("pause");
                return;
               }
               else break;
            }
            if(x==19){
                cout<<"\t\t#入住失敗!您選擇的房間不存在!"<<endl;
                system("pause");
                return;
            }
        }
        cout<<"\t\t#請輸入您預訂的個人信息: "<<endl;
        cout<<"\t\t#姓名: "; cin>>GuestName_;
        cout<<"\t\t#身份證號: "; cin>>GuestID_;
        if(room[x].GuestName!=GuestName_ || room[x].GuestID!=GuestID_){
            cout<<"\t\t#入住失敗!您輸入的信息不匹配!"<<endl;
            system("pause");
            return;
        }
        time_t CheckTime_;
        time(&CheckTime_);
        room[x].CheckInTime = ctime(&CheckTime_);
        room[x].CheckInTime = room[x].CheckInTime.substr(0, room[x].CheckInTime.length() - 1);
        room[x].IsChecked = true;

        fstream  file("操作員工作日誌.xls",ios::app);
        file<<UserName<<"\t"<<room[x].CheckInTime<<"\t入住房間\t"<<room[x].GuestName<<"\t"<<room[x].RoomNum<<endl;
        file.close();
        WriteRoomInformation(room);

        system("cls");
        cout<<"\t\t#入住成功!以下是您的入住信息: "<<endl;
        cout<<"\t\t#################################################"<<endl;
        cout<<"\t\t#\t\t@曾氏酒店客房管理系統@"<<endl;
        cout<<"\t\t#"<<endl;
        cout<<"\t\t#\t姓    名: "<<room[x].GuestName<<endl;
        cout<<"\t\t#\t身份證號: "<<room[x].GuestID<<endl;
        cout<<"\t\t#\t聯繫方式: "<<room[x].GuestTel<<endl;
        cout<<"\t\t#\t入住房號: "<<room[x].RoomNum<<endl;
        cout<<"\t\t#\t入住時間: "<<room[x].CheckInTime<<endl;
        cout<<"\t\t#"<<endl;
        cout<<"\t\t#################################################"<<endl;
        system("pause");
    }
    else
    {
        cout<<"\t\t#輸入錯誤!請輸入(Y/N)!"<<endl;
        system("pause");
    }
}

​ 測試界面如下:

酒店客房入住測試1.png

酒店客房入住測試2.png

酒店客房入住測試3.png

酒店客房入住測試4.png

酒店客房退房

​ 酒店客房退房的功能通過Operator::CheckOut函數實現。

​ 流程圖如下:

酒店客房退房.png

​ 實現源代碼如下:

void Operator::CheckOut(Room* room)
{
    int RoomNum_, x;
    cout<<"\t\t#請輸入您退房的房號: "; cin>>RoomNum_;
    for(x=0;x<20;x++){
        if(room[x].RoomNum==RoomNum_){
            if(room[x].IsChecked==false){
                cout<<"\t\t#退房失敗!您選擇的房間未入住!"<<endl;
                system("pause");
                return;
            }
            else break;
        }
        if(x==19){
            cout<<"\t\t#退房失敗!您選擇的房間不存在!"<<endl;
                system("pause");
            return;
        }
    }
    string GuestName_,GuestID_;
    cout<<"\t\t#請輸入您的個人信息: "<<endl;
    cout<<"\t\t#姓名: "; cin>>GuestName_;
    cout<<"\t\t#身份證號: "; cin>>GuestID_;
    if(room[x].GuestName!=GuestName_ || room[x].GuestID!=GuestID_){
        cout<<"\t\t#退房失敗!您輸入的信息不匹配!"<<endl;
        system("pause");
        return;
    }
    time_t CheckOutTime_;
    string CheckOutTime;
    time(&CheckOutTime_);
    CheckOutTime = ctime(&CheckOutTime_);
    CheckOutTime = CheckOutTime.substr(0, CheckOutTime.length() - 1);
    room[x].IsBooked = false;
    room[x].IsChecked = false;

    fstream  file("操作員工作日誌.xls",ios::app);
    file<<UserName<<"\t"<<CheckOutTime<<"\t住客退房\t"<<room[x].GuestName<<"\t"<<room[x].RoomNum<<endl;
    file.close();

    room[x].GuestName = "NULL";
    room[x].GuestID = "NULL";
    room[x].GuestTel = "NULL";
    room[x].BookTime = "NULL";
    room[x].CheckInTime = "NULL";
    WriteRoomInformation(room);
    cout<<"\t\t#退房成功!"<<endl;
    system("pause");
    return;
}

​ 測試界面如下:

酒店客房退房測試1.png

酒店客房退房測試2.png

三、課程設計總結

Pains

​ 在設計本系統的過程中,我花費了很多時間和心思讓該程序對用户更友好,努力設計使得程序更方便使用。在調試過程中我也遇到不少異常,包括由於編譯器編碼語言導致的程序運行異常,我查詢多篇文章後將所有異常解決,最終完成了本課程設計。

​ 在編寫本設計報告的過程中,發現自己的程序中,結構化設計等方面仍有不足,對於實際問題的解決還可以進一步改進(如增加金額結算功能等)。在後續的程序設計中,我會對本項目進行完善,達到更優。

​ 本程序設計花費了我不少心思,但是苦中有樂,我在編寫程序的過程中獲得了樂趣與滿足感,也進一步加深了自己對於程序設計的思考,有很大收穫。

Gains

​ 通過本系統的設計,我提高了分析和解決實際問題的能力,鞏固所學C++的知識,加強對結構化程序設計的思想。我全面系統地學習了面向對象程序設計的基本概念、基本語法和編程方法,獨立完成了有一定工作量的程序設計任務,強調好的程序設計風格。

附錄:設計代碼

include

Room.h

#ifndef ROOM_H
#define ROOM_H
#include <time.h>
#include<string>
#include <string.h>
#include<fstream>
using namespace std;

class Room
{
    public:
        Room();
        Room(int RoomNum_,string RoomType_,int RoomPrice_,bool IsBooked_,bool IsChecked_);

        friend void RoomInit(Room* room);
        friend class Administrator;
        friend class Operator;

    private:
        int RoomNum;
        string RoomType;
        int RoomPrice;
        bool IsBooked;
        bool IsChecked;

        string GuestName;
        string GuestID;
        string GuestTel;
        string BookTime;
        string CheckInTime;
};

#endif // ROOM_H

Operator.h

#ifndef OPERATOR_H
#define OPERATOR_H
#include "Room.h"
#include<string>
#include <string.h>
#include<fstream>
#include <iostream>
#include <Windows.h>
using namespace std;

class Operator
{
    public:
        Operator();
        string getUserName(){ return UserName; }
        void ViewRoomInformation(Room*);
        void WriteRoomInformation(Room*);
        void ReserveRoom(Room*);
        void CheckIn(Room*);
        void CheckOut(Room*);
        void RoomQuery(Room*);
        void BookQuery(Room*);
        void GuestQuery(Room*);
        void OperatorQuit();

        friend void OperatorInit(Operator* operators);
        friend int OperatorLogin(Operator* operators);

        friend class Administrator;

    private:
        string UserName;
        string Password;
};

#endif // OPERATOR_H

Administrator.h

#ifndef ADMINISTRATOR_H
#define ADMINISTRATOR_H
#include "Room.h"
#include "Operator.h"
#include <Windows.h>

class Administrator
{
    public:
        Administrator();

        friend bool AdministratorLogin(Administrator);

        void ViewOperatorInformation(Operator*);
        void WriteOperatorInformation(Operator*);
        void AddOperatorInformation(Operator*);
        void DeleteOperatorInformation(Operator*);
        void ModifyOperatorInformation(Operator*);
        void ViewRoomInformation(Room*);
        void ModifyRoomInformation(Room*);

    private:
        string UserName;
        string Password;
};

#endif // ADMINISTRATOR_H

src

Room.cpp

#include "Room.h"

Room::Room()
{
    RoomNum = 0;
    RoomType = "NULL";
    RoomPrice = 0;
    IsBooked = false;
    IsChecked = false;

    GuestName = "NULL";
    GuestID = "NULL";
    GuestTel = "NULL";
    BookTime = "NULL";
    CheckInTime = "NULL";
}
Room::Room(int RoomNum_,string RoomType_,int RoomPrice_,bool IsBooked_,bool IsChecked_)
{
    RoomNum = RoomNum_;
    RoomType = RoomType_;
    RoomPrice = RoomPrice_;
    IsBooked = IsBooked_;
    IsChecked = IsChecked_;
}

void RoomInit(Room* room)
{
    int StandardRoomNum = 8;
    int DoubleRoomNum = 7;
    int SuiteRoomNum = 20 - StandardRoomNum - DoubleRoomNum;
    int i[3]={1,0,1},k;

    for(k=0; k<20; k++)
    {
        room[k].RoomNum=i[0]*100+i[1]*10+i[2];
        switch(i[0])
        {
        case 1:{room[k].RoomPrice=150; room[k].RoomType="標間";break;}
        case 2:{room[k].RoomPrice=250; room[k].RoomType="雙人間";break;}
        case 3:{room[k].RoomPrice=500; room[k].RoomType="套房";break;}
        }
        if( k==(StandardRoomNum-1) )
            i[0]++,i[2]=0;
        if( k==(DoubleRoomNum+StandardRoomNum-1) )
            i[0]++,i[2]=0;
        i[2]++;
    }
    fstream  read("酒店房間信息.xls",ios::out);
    read<<"房間號\t類型\t價格\t是否預訂\t是否入住\t姓名\t身份證號\t聯繫方式\t預訂時間\t入住時間"<<endl;
    for(int x=0;x<20;x++)
    {
        read<<room[x].RoomNum<<"\t"<<room[x].RoomType<<"\t"<<room[x].RoomPrice<<"\t"<<room[x].IsBooked<<"\t"<<room[x].IsChecked<<"\t"<<room[x].GuestName
            <<"\t"<<room[x].GuestID<<"\t"<<room[x].GuestTel<<"\t"<<room[x].BookTime<<"\t"<<room[x].CheckInTime<<endl;
    }
    read.close();
}

Operator.cpp

#include "Operator.h"

Operator::Operator()
{
    UserName = "";
    Password = "";
}

void OperatorInit(Operator* operators)
{
    for(int k=0; k<10; k++)
    {
        operators[k].UserName = "zeng" + to_string(k);
        operators[k].Password = "000" + to_string(k);
    }
    fstream  read("操作員賬户信息.txt",ios::out);
    read<<"賬號\t密碼"<<endl;
    for(int x=0;x<10;x++)
    {
        read<<operators[x].UserName<<"\t"<<operators[x].Password<<endl;
    }
    read.close();
    fstream  file("操作員工作日誌.xls",ios::out);
    file<<"操作賬號\t操作時間\t操作內容\t操作對象\t操作房號"<<endl;
    file.close();
}

int OperatorLogin(Operator* operators)
{
    string UserName_,Password_;
    cout<<"\t\t#請輸入操作員賬號: ";
    cin>>UserName_;
    cout<<"\t\t#請輸入操作員密碼: ";
    cin>>Password_;
    for(int i=0; i<20; i++)
    {
        if( UserName_==operators[i].UserName && Password_==operators[i].Password ){
            time_t Time_;
            string Time;
            time(&Time_);
            Time = ctime(&Time_);
            Time = Time.substr(0, Time.length() - 1);

            fstream  file("操作員工作日誌.xls",ios::app);
            file<<operators[i].UserName<<"\t"<<Time<<"\t操作員登錄"<<endl;
            file.close();
            return i;
        }
    }
    return -1;
}

void Operator::OperatorQuit()
{
    cout<<"\t\t###################################"<<endl;
    cout<<"\t\t#      @曾氏酒店客房管理系統@     #"<<endl;
    cout<<"\t\t#                                 #"<<endl;
    cout<<"\t\t#              再見!             #"<<endl;
    cout<<"\t\t#        designed by 曾詩琦       #"<<endl;
    cout<<"\t\t#         LZU 320180943570        #"<<endl;
    cout<<"\t\t#                                 #"<<endl;
    cout<<"\t\t###################################"<<endl;
    time_t Time_;
    string Time;
    time(&Time_);
    Time = ctime(&Time_);
    Time = Time.substr(0, Time.length() - 1);

    fstream  file("操作員工作日誌.xls",ios::app);
    file<<UserName<<"\t"<<Time<<"\t操作員退出"<<endl;
    file.close();
}


void Operator::ViewRoomInformation(Room* room)
{
    int StandardRoomNum=0, DoubleRoomNum=0, SuiteRoomNum=0;
    int StandardRoomPrice=0, DoubleRoomPrice=0, SuiteRoomPrice=0;
    int StandardBookedNum=0, StandardCheckedNum=0;
    int DoubleBookedNum=0, DoubleCheckedNum=0;
    int SuiteBookedNum=0, SuiteCheckedNum=0;

    cout<<setw(4)<<setfill(' ')<<"房號"<<setw(7)<<setfill(' ')<<"類型 "<<setw(5)<<setfill(' ')<<"價格"
        <<setw(5)<<setfill(' ')<<"預訂"<<setw(5)<<setfill(' ')<<"入住";
    cout<<setw(8)<<setfill(' ')<<"姓名"<<setw(19)<<setfill(' ')<<"身份證號"<<setw(12)<<setfill(' ')<<"聯繫方式"<<endl;
    for(int x=0;x<20;x++){
        if(room[x].RoomNum!=0){
            if(room[x].RoomType=="標間"){
                StandardRoomPrice = room[x].RoomPrice;
                StandardRoomNum++;
                if(room[x].IsBooked) StandardBookedNum++;
                if(room[x].IsChecked) StandardCheckedNum++;
            }
            if(room[x].RoomType=="雙人間"){
                DoubleRoomPrice = room[x].RoomPrice;
                DoubleRoomNum++;
                if(room[x].IsBooked) DoubleBookedNum++;
                if(room[x].IsChecked) DoubleCheckedNum++;
            }
            if(room[x].RoomType=="套房"){
                SuiteRoomPrice = room[x].RoomPrice;
                SuiteRoomNum++;
                if(room[x].IsBooked) SuiteBookedNum++;
                if(room[x].IsChecked) SuiteCheckedNum++;
            }

            cout<<setw(4)<<setfill(' ')<<room[x].RoomNum<<setw(7)<<setfill(' ')<<room[x].RoomType<<setw(5)<<setfill(' ')<<room[x].RoomPrice;
            if(room[x].IsBooked) cout<<setw(5)<<setfill(' ')<<"是"; else cout<<setw(5)<<setfill(' ')<<"否";
            if(room[x].IsChecked) cout<<setw(5)<<setfill(' ')<<"是"; else cout<<setw(5)<<setfill(' ')<<"否";
            cout<<setw(8)<<setfill(' ')<<room[x].GuestName<<setw(19)<<setfill(' ')<<room[x].GuestID<<setw(12)<<setfill(' ')<<room[x].GuestTel<<endl;
        }
    }
    cout<<endl<<"##########################################"<<endl;
    cout<<"#"<<endl;
    cout<<"#\t\t# 酒店房間 #"<<endl;
    cout<<"#\t酒店房間共 "<<StandardRoomNum+DoubleRoomNum+SuiteRoomNum<<" 間"<<endl
         <<"#\t已預訂 "<<StandardBookedNum+DoubleBookedNum+SuiteBookedNum<<" 間\t未預訂 "<<StandardRoomNum+DoubleRoomNum+SuiteRoomNum-(StandardBookedNum+DoubleBookedNum+SuiteBookedNum)<<" 間"<<endl
         <<"#\t已入住 "<<StandardCheckedNum+DoubleCheckedNum+SuiteCheckedNum<<" 間\t未入住 "<<StandardRoomNum+DoubleRoomNum+SuiteRoomNum-(StandardCheckedNum+DoubleCheckedNum+SuiteCheckedNum)<<" 間"<<endl;
    cout<<"#"<<endl;
    cout<<"#\t\t# 標  間 #"<<endl;
    cout<<"#\t標間共 "<<StandardRoomNum<<" 間\t價格 "<<StandardRoomPrice<<" 元"<<endl
         <<"#\t已預訂 "<<StandardBookedNum<<" 間\t未預訂 "<<StandardRoomNum-StandardBookedNum<<" 間"<<endl
         <<"#\t已入住 "<<StandardCheckedNum<<" 間\t未入住 "<<StandardRoomNum-StandardCheckedNum<<" 間"<<endl;
    cout<<"#"<<endl;
    cout<<"#\t\t# 雙人間 #"<<endl;
    cout<<"#\t雙人間共 "<<DoubleRoomNum<<" 間\t價格 "<<DoubleRoomPrice<<" 元"<<endl
         <<"#\t已預訂 "<<DoubleBookedNum<<" 間\t未預訂 "<<DoubleRoomNum-DoubleBookedNum<<" 間"<<endl
         <<"#\t已入住 "<<DoubleCheckedNum<<" 間\t未入住 "<<DoubleRoomNum-DoubleCheckedNum<<" 間"<<endl;
    cout<<"#"<<endl;
    cout<<"#\t\t# 套  房 #"<<endl;
    cout<<"#\t套房共 "<<SuiteRoomNum<<" 間\t價格 "<<SuiteRoomPrice<<" 元"<<endl
         <<"#\t已預訂 "<<SuiteBookedNum<<" 間\t未預訂 "<<SuiteRoomNum-SuiteBookedNum<<" 間"<<endl
         <<"#\t已入住 "<<SuiteCheckedNum<<" 間\t未入住 "<<SuiteRoomNum-SuiteCheckedNum<<" 間"<<endl;
    cout<<"#"<<endl;
    cout<<"##########################################"<<endl;

    time_t Time_;
    string Time;
    time(&Time_);
    Time = ctime(&Time_);
    Time = Time.substr(0, Time.length() - 1);

    fstream  file("操作員工作日誌.xls",ios::app);
    file<<UserName<<"\t"<<Time<<"\t查看客房信息"<<endl;
    file.close();
}

void Operator::WriteRoomInformation(Room* room)
{
    fstream  read("酒店房間信息.xls",ios::out);
    read<<"房間號\t類型\t價格\t是否預訂\t是否入住\t姓名\t身份證號\t聯繫方式\t預訂時間\t入住時間"<<endl;
    for(int x=0;x<20;x++)
    {
        if(room[x].RoomNum!=0)
            read<<room[x].RoomNum<<"\t"<<room[x].RoomType<<"\t"<<room[x].RoomPrice<<"\t"<<room[x].IsBooked<<"\t"<<room[x].IsChecked<<"\t"<<room[x].GuestName
                <<"\t"<<room[x].GuestID<<"\t"<<room[x].GuestTel<<"\t"<<room[x].BookTime<<"\t"<<room[x].CheckInTime<<endl;
    }
    read.close();
}

void Operator::ReserveRoom(Room* room)
{
    int RoomNum_, x;
    cout<<"\t\t可預訂房間如下: "<<endl;
    cout<<"\t    ###########################"<<endl;
    cout<<"\t\t房間號\t類型\t價格"<<endl;
    for(x=0;x<20;x++){
        if(room[x].RoomNum!=0 && room[x].IsBooked==false && room[x].IsChecked==false){
            cout<<"\t\t"<<room[x].RoomNum<<"\t"<<room[x].RoomType<<"\t"<<room[x].RoomPrice<<endl;
        }
    }
    cout<<"\t    ###########################"<<endl;
    cout<<"\t\t#請選擇要預訂房間: "; cin>>RoomNum_;
    for(x=0;x<20;x++){
        if(room[x].RoomNum==RoomNum_){
           if(room[x].IsBooked==false && room[x].IsChecked==false) break;
           else {
            cout<<"\t\t#預訂失敗!您選擇的房間已被預訂!"<<endl;
            system("pause");
            return;
           }
        }
        if(x==19){
            cout<<"\t\t#預訂失敗!您選擇的房間已被預訂!"<<endl;
            system("pause");
            return;
        }
    }
    cout<<"\t\t#請輸入您的個人信息: "<<endl;
    cout<<"\t\t#姓名: "; cin>>room[x].GuestName;
    cout<<"\t\t#身份證號: "; cin>>room[x].GuestID;
    cout<<"\t\t#聯繫方式: "; cin>>room[x].GuestTel;
    time_t BookTime_;
    time(&BookTime_);
    room[x].BookTime = ctime(&BookTime_);
    room[x].BookTime = room[x].BookTime.substr(0, room[x].BookTime.length() - 1);
    room[x].IsBooked = true;

    fstream  file("操作員工作日誌.xls",ios::app);
    file<<UserName<<"\t"<<room[x].BookTime<<"\t預訂房間\t"<<room[x].GuestName<<"\t"<<room[x].RoomNum<<endl;
    file.close();
    WriteRoomInformation(room);

    system("cls");
    cout<<"\t\t#預訂成功!以下是您的預訂信息: "<<endl;
    cout<<"\t\t#################################################"<<endl;
    cout<<"\t\t#\t\t@曾氏酒店客房管理系統@"<<endl;
    cout<<"\t\t#"<<endl;
    cout<<"\t\t#\t姓    名: "<<room[x].GuestName<<endl;
    cout<<"\t\t#\t身份證號: "<<room[x].GuestID<<endl;
    cout<<"\t\t#\t聯繫方式: "<<room[x].GuestTel<<endl;
    cout<<"\t\t#\t預訂房號: "<<room[x].RoomNum<<endl;
    cout<<"\t\t#\t預訂時間: "<<room[x].BookTime<<endl;
    cout<<"\t\t#"<<endl;
    cout<<"\t\t#################################################"<<endl;
    system("pause");
}

void Operator::CheckIn(Room* room)
{
    char choose;
    int RoomNum_, x;
    string GuestName_, GuestID_;
    cout<<"\t\t#您是否已預訂了房間?(Y/N): ";
    cin>>choose;
    if(choose=='N'||choose=='n')
    {
        cout<<"\t\t#可入住房間如下: "<<endl;
        cout<<"\t    ###########################"<<endl;
        cout<<"\t\t房間號\t類型\t價格"<<endl;
        for(int x=0;x<20;x++){
            if(room[x].RoomNum!=0 && room[x].IsBooked==false && room[x].IsChecked==false){
                cout<<"\t\t"<<room[x].RoomNum<<"\t"<<room[x].RoomType<<"\t"<<room[x].RoomPrice<<endl;
            }
        }
        cout<<"\t    ###########################"<<endl;
        cout<<"\t\t#請選擇要入住房間: "; cin>>RoomNum_;
        int x;
        for(x=0;x<20;x++){
            if(room[x].RoomNum==RoomNum_){
               if(room[x].IsBooked==false && room[x].IsChecked==false) break;
               else {
                cout<<"\t\t#入住失敗!您選擇的房間已被預訂!"<<endl;
                system("pause");
                return;
               }
            }
            if(x==19){
                cout<<"\t\t#入住失敗!您選擇的房間已被預訂!"<<endl;
                system("pause");
                return;
            }
        }
        cout<<"\t\t#請輸入您的個人信息: "<<endl;
        cout<<"\t\t#姓名: "; cin>>room[x].GuestName;
        cout<<"\t\t#身份證號: "; cin>>room[x].GuestID;
        cout<<"\t\t#聯繫方式: "; cin>>room[x].GuestTel;
        time_t CheckTime_;
        time(&CheckTime_);
        room[x].CheckInTime = ctime(&CheckTime_);
        room[x].CheckInTime = room[x].CheckInTime.substr(0, room[x].CheckInTime.length() - 1);
        room[x].IsChecked = true;

        fstream  file("操作員工作日誌.xls",ios::app);
        file<<UserName<<"\t"<<room[x].CheckInTime<<"\t入住房間\t"<<room[x].GuestName<<"\t"<<room[x].RoomNum<<endl;
        file.close();
        WriteRoomInformation(room);

        system("cls");
        cout<<"\t\t#入住成功!以下是您的入住信息: "<<endl;
        cout<<"\t\t#################################################"<<endl;
        cout<<"\t\t#\t\t@曾氏酒店客房管理系統@"<<endl;
        cout<<"\t\t#"<<endl;
        cout<<"\t\t#\t姓    名: "<<room[x].GuestName<<endl;
        cout<<"\t\t#\t身份證號: "<<room[x].GuestID<<endl;
        cout<<"\t\t#\t聯繫方式: "<<room[x].GuestTel<<endl;
        cout<<"\t\t#\t入住房號: "<<room[x].RoomNum<<endl;
        cout<<"\t\t#\t入住時間: "<<room[x].CheckInTime<<endl;
        cout<<"\t\t#"<<endl;
        cout<<"\t\t#################################################"<<endl;
        system("pause");
    }
    else if(choose=='Y'||choose=='y')
    {
        cout<<"\t\t#請輸入您預訂的房號: "; cin>>RoomNum_;
        for(x=0;x<20;x++){
            if(room[x].RoomNum==RoomNum_){
               if(room[x].IsBooked==false){
                cout<<"\t\t#入住失敗!您選擇的房間未被預訂!"<<endl;
                system("pause");
                return;
               }
               else if(room[x].IsChecked==true){
                cout<<"\t\t#入住失敗!您選擇的房間已入住!"<<endl;
                system("pause");
                return;
               }
               else break;
            }
            if(x==19){
                cout<<"\t\t#入住失敗!您選擇的房間不存在!"<<endl;
                system("pause");
                return;
            }
        }
        cout<<"\t\t#請輸入您預訂的個人信息: "<<endl;
        cout<<"\t\t#姓名: "; cin>>GuestName_;
        cout<<"\t\t#身份證號: "; cin>>GuestID_;
        if(room[x].GuestName!=GuestName_ || room[x].GuestID!=GuestID_){
            cout<<"\t\t#入住失敗!您輸入的信息不匹配!"<<endl;
            system("pause");
            return;
        }
        time_t CheckTime_;
        time(&CheckTime_);
        room[x].CheckInTime = ctime(&CheckTime_);
        room[x].CheckInTime = room[x].CheckInTime.substr(0, room[x].CheckInTime.length() - 1);
        room[x].IsChecked = true;

        fstream  file("操作員工作日誌.xls",ios::app);
        file<<UserName<<"\t"<<room[x].CheckInTime<<"\t入住房間\t"<<room[x].GuestName<<"\t"<<room[x].RoomNum<<endl;
        file.close();
        WriteRoomInformation(room);

        system("cls");
        cout<<"\t\t#入住成功!以下是您的入住信息: "<<endl;
        cout<<"\t\t#################################################"<<endl;
        cout<<"\t\t#\t\t@曾氏酒店客房管理系統@"<<endl;
        cout<<"\t\t#"<<endl;
        cout<<"\t\t#\t姓    名: "<<room[x].GuestName<<endl;
        cout<<"\t\t#\t身份證號: "<<room[x].GuestID<<endl;
        cout<<"\t\t#\t聯繫方式: "<<room[x].GuestTel<<endl;
        cout<<"\t\t#\t入住房號: "<<room[x].RoomNum<<endl;
        cout<<"\t\t#\t入住時間: "<<room[x].CheckInTime<<endl;
        cout<<"\t\t#"<<endl;
        cout<<"\t\t#################################################"<<endl;
        system("pause");
    }
    else
    {
        cout<<"\t\t#輸入錯誤!請輸入(Y/N)!"<<endl;
        system("pause");
    }
}

void Operator::CheckOut(Room* room)
{
    int RoomNum_, x;
    cout<<"\t\t#請輸入您退房的房號: "; cin>>RoomNum_;
    for(x=0;x<20;x++){
        if(room[x].RoomNum==RoomNum_){
            if(room[x].IsChecked==false){
                cout<<"\t\t#退房失敗!您選擇的房間未入住!"<<endl;
                system("pause");
                return;
            }
            else break;
        }
        if(x==19){
            cout<<"\t\t#退房失敗!您選擇的房間不存在!"<<endl;
                system("pause");
            return;
        }
    }
    string GuestName_,GuestID_;
    cout<<"\t\t#請輸入您的個人信息: "<<endl;
    cout<<"\t\t#姓名: "; cin>>GuestName_;
    cout<<"\t\t#身份證號: "; cin>>GuestID_;
    if(room[x].GuestName!=GuestName_ || room[x].GuestID!=GuestID_){
        cout<<"\t\t#退房失敗!您輸入的信息不匹配!"<<endl;
        system("pause");
        return;
    }
    time_t CheckOutTime_;
    string CheckOutTime;
    time(&CheckOutTime_);
    CheckOutTime = ctime(&CheckOutTime_);
    CheckOutTime = CheckOutTime.substr(0, CheckOutTime.length() - 1);
    room[x].IsBooked = false;
    room[x].IsChecked = false;

    fstream  file("操作員工作日誌.xls",ios::app);
    file<<UserName<<"\t"<<CheckOutTime<<"\t住客退房\t"<<room[x].GuestName<<"\t"<<room[x].RoomNum<<endl;
    file.close();

    room[x].GuestName = "NULL";
    room[x].GuestID = "NULL";
    room[x].GuestTel = "NULL";
    room[x].BookTime = "NULL";
    room[x].CheckInTime = "NULL";
    WriteRoomInformation(room);
    cout<<"\t\t#退房成功!"<<endl;
    system("pause");
    return;
}

void Operator::BookQuery(Room* room)
{
    int RoomNum_, x;
    string GuestName_;
    cout<<"\t\t#請輸入您預訂的房號: "; cin>>RoomNum_;
    cout<<"\t\t#請輸入您預訂的姓名: "; cin>>GuestName_;
    for(x=0;x<20;x++){
        if(room[x].RoomNum==RoomNum_){
            if(room[x].IsBooked==false){
                cout<<"\t\t#查詢失敗!您選擇的房間未被預訂!"<<endl;
                system("pause");
                return;
            }
            else if(room[x].IsChecked==true){
                cout<<"\t\t#查詢失敗!您選擇的房間已入住!"<<endl;
                system("pause");
                return;
            }
            else if(room[x].GuestName!=GuestName_){
                cout<<"\t\t#查詢失敗!您輸入的信息不匹配!"<<endl;
                system("pause");
                return;
            }
            else break;
        }
        if(x==19){
            cout<<"\t\t#查詢失敗!您選擇的房間不存在!"<<endl;
            system("pause");
            return;
        }
    }
    system("cls");
    cout<<"\t\t#查詢成功!以下是您的預訂信息: "<<endl;
    cout<<"\t\t#################################################"<<endl;
    cout<<"\t\t#\t\t@曾氏酒店客房管理系統@"<<endl;
    cout<<"\t\t#"<<endl;
    cout<<"\t\t#\t姓    名: "<<room[x].GuestName<<endl;
    cout<<"\t\t#\t身份證號: "<<room[x].GuestID<<endl;
    cout<<"\t\t#\t聯繫方式: "<<room[x].GuestTel<<endl;
    cout<<"\t\t#\t預訂房號: "<<room[x].RoomNum<<endl;
    cout<<"\t\t#\t預訂時間: "<<room[x].BookTime<<endl;
    cout<<"\t\t#"<<endl;
    cout<<"\t\t#################################################"<<endl;
    system("pause");

    time_t Time_;
    string Time;
    time(&Time_);
    Time = ctime(&Time_);
    Time = Time.substr(0, Time.length() - 1);

    fstream  file("操作員工作日誌.xls",ios::app);
    file<<UserName<<"\t"<<Time<<"\t預訂查詢"<<endl;
    file.close();
}

void Operator::RoomQuery(Room* room)
{
    int RoomNum_, x;
    cout<<"\t\t#請輸入您查詢的房號: "; cin>>RoomNum_;
    for(x=0;x<20;x++){
        if(room[x].RoomNum==RoomNum_){
            break;
        }
        if(x==19){
            cout<<"\t\t#查詢失敗!您選擇的房間不存在!"<<endl;
            system("pause");
            return;
        }
    }
    system("cls");
    cout<<"\t\t#查詢成功!以下是您的查詢信息: "<<endl;
    cout<<"\t\t#################################################"<<endl;
    cout<<"\t\t#\t\t@曾氏酒店客房管理系統@"<<endl;
    cout<<"\t\t#"<<endl;
    cout<<"\t\t#\t房 間 號: "<<room[x].RoomNum<<endl;
    cout<<"\t\t#\t房間類型: "<<room[x].RoomType<<endl;
    cout<<"\t\t#\t房間價格: "<<room[x].RoomPrice<<endl;
    cout<<"\t\t#\t是否預訂: ";      if(room[x].IsBooked) cout<<"是"<<endl; else cout<<"否"<<endl;
    cout<<"\t\t#\t是否入住: ";      if(room[x].IsChecked) cout<<"是"<<endl; else cout<<"否"<<endl;
    if(room[x].IsChecked)
    {
    cout<<"\t\t#\t姓    名: "<<room[x].GuestName<<endl;
    cout<<"\t\t#\t身份證號: "<<room[x].GuestID<<endl;
    cout<<"\t\t#\t聯繫方式: "<<room[x].GuestTel<<endl;
    cout<<"\t\t#\t入住時間: "<<room[x].CheckInTime<<endl;
    }
    else if(room[x].IsBooked)
    {
    cout<<"\t\t#\t姓    名: "<<room[x].GuestName<<endl;
    cout<<"\t\t#\t身份證號: "<<room[x].GuestID<<endl;
    cout<<"\t\t#\t聯繫方式: "<<room[x].GuestTel<<endl;
    cout<<"\t\t#\t預訂時間: "<<room[x].BookTime<<endl;
    }
    cout<<"\t\t#"<<endl;
    cout<<"\t\t#################################################"<<endl;
    system("pause");

    time_t Time_;
    string Time;
    time(&Time_);
    Time = ctime(&Time_);
    Time = Time.substr(0, Time.length() - 1);

    fstream  file("操作員工作日誌.xls",ios::app);
    file<<UserName<<"\t"<<Time<<"\t客房查詢"<<endl;
    file.close();
}

void Operator::GuestQuery(Room* room)
{
    int x;
    string GuestName_;
    cout<<"\t\t#請輸入您查詢的客户姓名: "; cin>>GuestName_;
    for(x=0;x<20;x++){
        if(room[x].GuestName==GuestName_){
            break;
        }
        if(x==19){
            cout<<"\t\t#查詢失敗!您查詢的客户不存在!"<<endl;
            system("pause");
            return;
        }
    }
    system("cls");
    cout<<"\t\t#查詢成功!以下是您的查詢信息: "<<endl;
    cout<<"\t\t#################################################"<<endl;
    cout<<"\t\t#\t\t@曾氏酒店客房管理系統@"<<endl;
    cout<<"\t\t#"<<endl;
    cout<<"\t\t#\t姓    名: "<<room[x].GuestName<<endl;
    cout<<"\t\t#\t身份證號: "<<room[x].GuestID<<endl;
    cout<<"\t\t#\t聯繫方式: "<<room[x].GuestTel<<endl;
    cout<<"\t\t#\t是否預訂: ";      if(room[x].IsBooked) cout<<"是"<<endl; else cout<<"否"<<endl;
    cout<<"\t\t#\t是否入住: ";      if(room[x].IsChecked) cout<<"是"<<endl; else cout<<"否"<<endl;
    if(room[x].IsChecked)
    {
    cout<<"\t\t#\t入住房號: "<<room[x].RoomNum<<endl;
    cout<<"\t\t#\t房間類型: "<<room[x].RoomType<<endl;
    cout<<"\t\t#\t房間價格: "<<room[x].RoomPrice<<endl;
    cout<<"\t\t#\t入住時間: "<<room[x].CheckInTime<<endl;
    }
    else if(room[x].IsBooked)
    {
    cout<<"\t\t#\t預訂房號: "<<room[x].RoomNum<<endl;
    cout<<"\t\t#\t房間類型: "<<room[x].RoomType<<endl;
    cout<<"\t\t#\t房間價格: "<<room[x].RoomPrice<<endl;
    cout<<"\t\t#\t預訂時間: "<<room[x].BookTime<<endl;
    }
    cout<<"\t\t#"<<endl;
    cout<<"\t\t#################################################"<<endl;
    system("pause");

    time_t Time_;
    string Time;
    time(&Time_);
    Time = ctime(&Time_);
    Time = Time.substr(0, Time.length() - 1);

    fstream  file("操作員工作日誌.xls",ios::app);
    file<<UserName<<"\t"<<Time<<"\t客户查詢"<<endl;
    file.close();
}

Administrator.cpp

#include "Administrator.h"

Administrator::Administrator()
{
    UserName = "zsq";
    Password = "000";
}

bool AdministratorLogin(Administrator a)
{
    string UserName_,Password_;
    cout<<"\t\t#請輸入管理員賬號: ";
    cin>>UserName_;
    cout<<"\t\t#請輸入管理員密碼: ";
    cin>>Password_;
    if( UserName_==a.UserName && Password_==a.Password )
        return true;
    else return false;
}

void Administrator::ViewOperatorInformation(Operator* operators)
{
    int num = 0;
    cout<<"\t\t序號\t賬號\t密碼"<<endl;
    for(int x=0;x<20;x++){
        if(operators[x].UserName!=""){
            num++;
            cout<<"\t\t"<<num<<": \t"<<operators[x].UserName<<"\t"<<operators[x].Password<<endl;
        }
    }
}

void Administrator::WriteOperatorInformation(Operator* operators)
{
    fstream  read("操作員賬户信息.txt",ios::out);
    read<<"賬號\t密碼"<<endl;
    for(int x=0;x<20;x++)
    {
        if(operators[x].UserName!="")
            read<<operators[x].UserName<<"\t"<<operators[x].Password<<endl;
    }
    read.close();
}

void Administrator::AddOperatorInformation(Operator* operators)
{
    string UserName_,Password_;
    for(int x=0;x<20;x++){
        if(operators[x].UserName==""){
            cout<<"\t\t#請輸入新增操作員賬號: ";
            cin>>UserName_; operators[x].UserName=UserName_;
            cout<<"\t\t#請輸入新增操作員密碼: ";
            cin>>Password_; operators[x].Password=Password_;
            WriteOperatorInformation(operators);
            break;
        }
    }
}

void Administrator::DeleteOperatorInformation(Operator* operators)
{
    ViewOperatorInformation(operators);
    int choose;
    cout<<"\t\t#請選擇要刪除的操作員信息的序號: ";
    cin>>choose;
    int num = choose;
    for(int x=0;x<choose;x++){
        if(operators[x].UserName==""){
            num++;
        }
    }
    if(operators[num-1].UserName==""){
        cout<<"\t\t#刪除失敗!該操作員不存在!"<<endl;
        system("pause");
        return;
    }
    operators[num-1].UserName="";
    operators[num-1].Password="";
    WriteOperatorInformation(operators);
}

void Administrator::ModifyOperatorInformation(Operator* operators)
{
    ViewOperatorInformation(operators);
    int choose;
    string UserName_,Password_;
    cout<<"\t\t#請選擇要修改的操作員信息的序號: ";
    cin>>choose;
    int num = choose;
    for(int x=0;x<=choose;x++){
        if(operators[x].UserName==""){
            num++;
        }
    }
    if(operators[num-1].UserName==""){
        cout<<"\t\t#修改失敗!該操作員不存在!"<<endl;
        system("pause");
        return;
    }
    cout<<"\t\t#請輸入修改操作員賬號: ";
    cin>>UserName_; operators[num-1].UserName=UserName_;
    cout<<"\t\t#請輸入修改操作員密碼: ";
    cin>>Password_; operators[num-1].Password=Password_;
    WriteOperatorInformation(operators);
}

void Administrator::ViewRoomInformation(Room* room)
{
    cout<<"\t\t房間號\t類型\t價格"<<endl;
    for(int x=0;x<20;x++){
        if(room[x].RoomNum!=0){
            cout<<"\t\t"<<room[x].RoomNum<<"\t"<<room[x].RoomType<<"\t"<<room[x].RoomPrice<<endl;
        }
    }
}

void Administrator::ModifyRoomInformation(Room* room)
{
    int StandardRoomNum, StandardRoomPrice;
    int DoubleRoomNum, DoubleRoomPrice;
    int SuiteRoomNum, SuiteRoomPrice;
    cout<<"\t\t#由於本酒店客房有限,請確保輸入房間總數≤20。"<<endl<<endl;
    cout<<"\t\t#請輸入標間個數: "; cin>>StandardRoomNum;
    cout<<"\t\t#請輸入標間價格: "; cin>>StandardRoomPrice;
    cout<<endl;
    cout<<"\t\t#請輸入雙人間個數: "; cin>>DoubleRoomNum;
    cout<<"\t\t#請輸入雙人間價格: "; cin>>DoubleRoomPrice;
    cout<<endl;
    cout<<"\t\t#請輸入套房個數: "; cin>>SuiteRoomNum;
    cout<<"\t\t#請輸入套房價格: "; cin>>SuiteRoomPrice;
    cout<<endl;
    if(StandardRoomNum+DoubleRoomNum+SuiteRoomNum>20){
        cout<<"\t\t#修改失敗!您輸入的房間個數超出本酒店的房間上限!請保證房間總數≤20!"<<endl;
        system("pause");
        return;
    }
    int i[3]={1,0,1},k;
    for(k=0; k<20; k++)
    {
        room[k].RoomNum = 0;
        room[k].RoomType = "NULL";
        room[k].RoomPrice = 0;
        room[k].IsBooked = false;
        room[k].IsChecked = false;

        room[k].GuestName = "NULL";
        room[k].GuestID = "NULL";
        room[k].GuestTel = "NULL";
        room[k].CheckInTime = "NULL";
        room[k].BookTime = "NULL";
    }
    for(k=0; k<(StandardRoomNum+DoubleRoomNum+SuiteRoomNum); k++)
    {
        room[k].RoomNum=i[0]*100+i[1]*10+i[2];
        switch(i[0])
        {
        case 1:{room[k].RoomPrice=StandardRoomPrice; room[k].RoomType="標間";break;}
        case 2:{room[k].RoomPrice=DoubleRoomPrice; room[k].RoomType="雙人間";break;}
        case 3:{room[k].RoomPrice=SuiteRoomPrice; room[k].RoomType="套房";break;}
        }
        if( k==(StandardRoomNum-1) )
            i[0]++,i[2]=0;
        if( k==(DoubleRoomNum+StandardRoomNum-1) )
            i[0]++,i[2]=0;
        i[2]++;
    }
    fstream  read("酒店房間信息.xls",ios::out);
    read<<"房間號\t類型\t價格\t是否預訂\t是否入住\t姓名\t身份證號\t聯繫方式\t預訂時間\t入住時間"<<endl;
    for(int x=0;x<StandardRoomNum+DoubleRoomNum+SuiteRoomNum;x++)
    {
        read<<room[x].RoomNum<<"\t"<<room[x].RoomType<<"\t"<<room[x].RoomPrice<<"\t"<<room[x].IsBooked<<"\t"<<room[x].IsChecked<<"\t"<<room[x].GuestName
            <<"\t"<<room[x].GuestID<<"\t"<<room[x].GuestTel<<"\t"<<room[x].BookTime<<"\t"<<room[x].CheckInTime<<endl;
    }
    read.close();
    cout<<"\t\t#修改成功!"<<endl;
    system("pause");
    return;
}

main.cpp

#include "Room.h"
#include "Administrator.h"
#include "Operator.h"
#include <iostream>
#include <Windows.h>
using namespace std;

int main()
{
    int choose=0;
    int flag;
    int i;//操作員的序號

    //房間初始化
    Room room[20];
    RoomInit(room);

    //管理員初始化
    Administrator a = Administrator();

    //操作員初始化
    Operator operators[20];
    OperatorInit(operators);

    while(true)
    {
    flag = 1;
    system("cls");
    cout<<"\t\t###################################"<<endl;
    cout<<"\t\t#      @曾氏酒店客房管理系統@     #"<<endl;
    cout<<"\t\t#                                 #"<<endl;
    cout<<"\t\t#           1.管理員登錄          #"<<endl;
    cout<<"\t\t#           2.操作員登錄          #"<<endl;
    cout<<"\t\t#           3.查看幫助            #"<<endl;
    cout<<"\t\t#           4.關於本系統          #"<<endl;
    cout<<"\t\t#           5.退出系統            #"<<endl;
    cout<<"\t\t#                                 #"<<endl;
    cout<<"\t\t###################################"<<endl;
    cout<<"\t\t#請選擇: ";
    cin>>choose;
    system("cls");
    switch(choose)
    {
        case 1:
            if( !AdministratorLogin(a) ){
                cout<<"\t\t#登錄失敗!若忘記密碼可【查看幫助】!"<<endl;;
                system("pause");
                break;
            }
            else{
                cout<<"\t\t#登錄成功!"<<endl;
                system("pause");
            }
            while(flag)
            {
            system("cls");
            cout<<"\t\t#管理員,您好!"<<endl;
            cout<<"\t\t###################################"<<endl;
            cout<<"\t\t#      @曾氏酒店客房管理系統@     #"<<endl;
            cout<<"\t\t#                                 #"<<endl;
            cout<<"\t\t#         1.查看操作員信息        #"<<endl;
            cout<<"\t\t#         2.增加操作員信息        #"<<endl;
            cout<<"\t\t#         3.刪除操作員信息        #"<<endl;
            cout<<"\t\t#         4.修改操作員信息        #"<<endl;
            cout<<"\t\t#         5.查看酒店客房信息      #"<<endl;
            cout<<"\t\t#         6.修改酒店客房信息      #"<<endl;
            cout<<"\t\t#         7.返回上級目錄          #"<<endl;
            cout<<"\t\t#                                 #"<<endl;
            cout<<"\t\t###################################"<<endl;
            cout<<"\t\t#請選擇:";
            cin>>choose;
            system("cls");
            switch(choose)
            {
                case 1:
                    a.ViewOperatorInformation(operators);
                    system("pause");
                    break;
                case 2:
                    a.AddOperatorInformation(operators);
                    break;
                case 3:
                    a.DeleteOperatorInformation(operators);
                    break;
                case 4:
                    a.ModifyOperatorInformation(operators);
                    break;
                case 5:
                    a.ViewRoomInformation(room);
                    system("pause");
                    break;
                case 6:
                    a.ModifyRoomInformation(room);
                    break;
                case 7:
                    flag = 0; break;
                default: break;
            }
            }
            break;

        case 2:
            i=OperatorLogin(operators);
            if( i<0 ){
                cout<<"\t\t#登錄失敗!若忘記密碼可【查看幫助】!"<<endl;
                system("pause");
                break;
            }
            else{
                cout<<"\t\t#登錄成功!"<<endl;
                system("pause");
            }
            while(flag)
            {
            system("cls");
            cout<<"\t\t#操作員"<<operators[i].getUserName()<<",您好!"<<endl;
            cout<<"\t\t###################################"<<endl;
            cout<<"\t\t#      @曾氏酒店客房管理系統@     #"<<endl;
            cout<<"\t\t#                                 #"<<endl;
            cout<<"\t\t#          1.查看客房信息         #"<<endl;
            cout<<"\t\t#          2.預 訂 房 間          #"<<endl;
            cout<<"\t\t#          3.入 住 房 間          #"<<endl;
            cout<<"\t\t#          4.住 客 退 房          #"<<endl;
            cout<<"\t\t#          5.預 訂 查 詢          #"<<endl;
            cout<<"\t\t#          6.房 間 查 詢          #"<<endl;
            cout<<"\t\t#          7.住 客 查 詢          #"<<endl;
            cout<<"\t\t#          8.返回上級目錄         #"<<endl;
            cout<<"\t\t#          9.退 出 系 統          #"<<endl;
            cout<<"\t\t#                                 #"<<endl;
            cout<<"\t\t###################################"<<endl;
            cout<<"\t\t#請選擇:";
            cin>>choose;
            system("cls");
            switch(choose)
            {
                case 1:
                    operators[i].ViewRoomInformation(room);
                    system("pause");
                    break;
                case 2:
                    operators[i].ReserveRoom(room);
                    break;
                case 3:
                    operators[i].CheckIn(room);
                    break;
                case 4:
                    operators[i].CheckOut(room);
                    break;
                case 5:
                    operators[i].BookQuery(room);
                    break;
                case 6:
                    operators[i].RoomQuery(room);
                    break;
                case 7:
                    operators[i].GuestQuery(room);
                    break;
                case 8:
                    operators[i].OperatorQuit();
                    flag = 0; break;
                case 9:
                    operators[i].OperatorQuit();
                    return 0;
                default: break;
            }
            }
            break;

        case 3:
            cout<<"\t\t#####################################################"<<endl;
            cout<<"\t\t#\t\t@曾氏酒店客房管理系統@"<<endl;
            cout<<"\t\t#\t\t      @查看幫助@"<<endl;
            cout<<"\t\t#"<<endl;
            cout<<"\t\t#\t管理員賬號: zsq"<<endl;
            cout<<"\t\t#\t管理員密碼: 000"<<endl;
            cout<<"\t\t#"<<endl;
            cout<<"\t\t#\t操作員賬號: 請登錄管理員賬號後修改或查詢"<<endl;
            cout<<"\t\t#\t操作員密碼: 請登錄管理員賬號後修改或查詢"<<endl;
            cout<<"\t\t#"<<endl;
            cout<<"\t\t#####################################################"<<endl;
            system("pause");
            break;

        case 4:
            cout<<"\t################################################################"<<endl;
            cout<<"\t#\t\t@曾氏酒店客房管理系統@"<<endl;
            cout<<"\t#\t\t     @關於本系統@"<<endl;
            cout<<"\t#\t"<<endl;
            cout<<"\t#\t類:"<<endl;
            cout<<"\t#\t\tAdministrator - 管理員"<<endl;
            cout<<"\t#\t\tOperator      - 操作員"<<endl;
            cout<<"\t#\t\tRoom          - 客房"<<endl;
            cout<<"\t#\t"<<endl;
            cout<<"\t#\t初始化: "<<endl;
            cout<<"\t#\t\t管理員賬號密碼 - 賬號=zsq,密碼=000"<<endl;
            cout<<"\t#\t\t操作員賬號密碼 - 初始化10個,參見\"操作員賬號信息.txt\""<<endl;
            cout<<"\t#\t\t客房數量價格   - 初始化20個,參見\"酒店房間信息.xlsx\""<<endl;
            cout<<"\t#\t"<<endl;
            cout<<"\t#\t修改信息: "<<endl;
            cout<<"\t#\t\t修改管理員信息 - 不可修改,賬號=zsq,密碼=000"<<endl;
            cout<<"\t#\t\t修改操作員信息 - 登錄管理員賬號進行修改"<<endl;
            cout<<"\t#\t\t修改客房信息   - 登錄管理員賬號進行修改"<<endl;
            cout<<"\t#\t"<<endl;
            cout<<"\t#\t管理員操作:"<<endl;
            cout<<"\t#\t\t1.查看操作員信息"<<endl;
            cout<<"\t#\t\t2.增加操作員信息"<<endl;
            cout<<"\t#\t\t3.刪除操作員信息"<<endl;
            cout<<"\t#\t\t4.修改操作員信息"<<endl;
            cout<<"\t#\t\t5.查看酒店客房信息"<<endl;
            cout<<"\t#\t\t6.修改酒店客房信息"<<endl;
            cout<<"\t#\t"<<endl;
            cout<<"\t#\t操作員操作:"<<endl;
            cout<<"\t#\t\t1.查看客房信息"<<endl;
            cout<<"\t#\t\t2.預 訂 房 間"<<endl;
            cout<<"\t#\t\t3.入 住 房 間"<<endl;
            cout<<"\t#\t\t4.住 客 退 房"<<endl;
            cout<<"\t#\t\t5.預 訂 查 詢"<<endl;
            cout<<"\t#\t\t6.房 間 查 詢"<<endl;
            cout<<"\t#\t\t7.住 客 查 詢"<<endl;
            cout<<"\t#\t"<<endl;
            cout<<"\t#\t文件信息:"<<endl;
            cout<<"\t#\t\t操作員賬號信息.txt  - 操作員賬號和密碼"<<endl;
            cout<<"\t#\t\t酒店房間信息.xlsx   - 酒店房間的各種信息"<<endl;
            cout<<"\t#\t\t操作員工作日誌.xlsx - 操作員所有操作"<<endl;
            cout<<"\t#\t"<<endl;
            cout<<"\t################################################################"<<endl;
            system("pause");
            break;

        case 5:
            cout<<"\t\t###################################"<<endl;
            cout<<"\t\t#      @曾氏酒店客房管理系統@     #"<<endl;
            cout<<"\t\t#                                 #"<<endl;
            cout<<"\t\t#              再見!             #"<<endl;
            cout<<"\t\t#        designed by 曾詩琦       #"<<endl;
            cout<<"\t\t#         LZU 320180943570        #"<<endl;
            cout<<"\t\t#                                 #"<<endl;
            cout<<"\t\t###################################"<<endl;
            return 0;

        default : break;
        }
    }
    return 0;
}
user avatar
0 位用戶收藏了這個故事!

發佈 評論

Some HTML is okay.