2

一、功能描述

本项目为“酒店客房管理系统”,实现了对酒店的客房信息进行管理,主要功能包括:

  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;
}

ShadowCK
51 声望9 粉丝

这个人是个萌新,什么都没有留下。