宾馆房间管理系统——C++代码

1.问题描述

设计一个程序实现对宾馆房间的基本管理

2.基本要求

可以实现:客房信息的录入功能;客人入住登记、客人退房结算;客房信息浏览功能,浏览全部客户的信息,客房信息和客户信息分别保存于不同文件;客房信息查询,查询空房间情况,实现按房间号查询等。

3.需求分析

程序可以输入客房及客户信息,并查询。输入提示数字,即可进行相应功能。

4.概要设计

房间信息的录入:可以完成对客房信息的录入,修改,删除等。

顾客入住房间登记:可以完成对客户信息的录入,修改,删除等。

所有房间信息查询:可以随时查询房间当前的信息。

所有顾客的显示:可以查询顾客的身份信息。

5.详细设计

#include<iostream>

#include<fstream>

#include<string>

#include<iomanip>

#include<windows.h>

#include<conio.h>

#define Max 100

using namespace std;

class Data//日期类,记录交易时间

{

    public:

        Data(){}//缺省构造函数

        ~Data(){}//析构函数

        void SetDate(int year,int month,int day)//接收输入的日期

        {

            this->year=year;

            this->month=month;

            this->day=day;

         }

         int getyear(){

             return year;

         }

        int getmonth(){

             return month;

         }

        int getday(){

             return day;

         }

    private:

        int year;

        int month;

        int day;

};

class Room

{

    public:

        Room *r[Max];//房间对象指针数组                                    

        int Room_count;    //记录房间数量    

        Room(int Number,string Type,double Price,string Whether)//构造函数

        {

            this->Number=Number;

            this->Type=Type;

            this->Whether=Whether;

            this->Price=Price;

                    }

        int InputNumber()    {return Number;}

        string InputType(){return Type;}

        string InputWhether(){return Whether;}

        double InputPrice(){return Price;}

        void SetWether(string _state)    {Whether=_state;}

        void show()    {cout<<"房号:  "<<Number<<"\t"<<"房间类型:  "<<Type<<"\t"<<"房间状态:  "<<Whether<<"\t"<<"价格:   "<<Price<<endl;}    

    protected:

        int Number; //房号

        string Type;//类型

        string Whether;//是否有客人

        double Price;//价格

             

};

class Guest

{

    public:

        Guest *g[Max];    //客人对象指针数组                                

        int Guest_count;    //记录客人数量    

        Guest(int number,string Name,int Id,string sex,string Intime,int days) //构造函数

        {

            this->Name=Name;    this->Id=Id;    this->sex=sex; this->number=number;

            this->Intime=Intime;    this->days=days;

        }

        int InputNumber(){return number;}

        string InputName(){return Name;}

        string InputSex(){return sex;}

        int InputDays(){return days;}

        string InputIntime(){return Intime;}

        int InputId(){return Id;}

        void show()

        {

            cout<<"顾客姓名:  "<<Name<<"\t 身份证号:  "<<Id<<"\t性别:  "<<sex<<"\t入住时间:  "<<Intime<<"\t入住天数:  "<<days<<endl;

        }

    protected:

        int number;//房号

        string Name;//顾客姓名

        int Id;//身份证号

        string sex;//性别

        string Intime;//入住时间

        int days; //入住天数

};

class Manage

{

    public:    

        Guest *g[Max];    //客人对象指针数组                                

        int Guest_count;    //记录客人数量        

        Room *r[Max];//房间对象指针数组                                    

        int Room_count;    //记录房间数量

    /*操作函数*/

        void IncreaseRoom();//添加客房信息

        void Check_In();    //删除客房信息,办理入住

        void Check_Out();    //退房    

        int Payment();//结账

        void Display(int n);//浏览所有信息(1浏览房间,2浏览顾客)                 

        void ReadData();  //从文件中获取房间和顾客的信息

        void WriteData(int n);//向文件中写入所有的信息

        void WriteRoom(Room *r);//客房信息写入

        void WriteGuest(Guest *g);//顾客信息写入

    /*查询菜单 */

        void SearchMenu();//查询主菜单

        void SearchType();//查询所有空房间;

        void SearchNumber();//按房间号查询        

};

static int i=0;

void Manage::SearchMenu()

{

    int n;

    system("cls");

    cout<<"===================================="<<endl;

    cout<<"=         查   询   菜   单        ="<<endl;

    cout<<"===================================="<<endl;

    cout<<"=========  1、查 询 空 房    ======="<<endl;

    cout<<"=========  2、按房间号查询   ======="<<endl;

    cout<<"===================================="<<endl;

    cout<<endl<<"请选择: ";

    cin>>n;

    switch(n)

    {

        case 1:SearchType(); break;

        case 2:SearchNumber();break;

    }

 }

void Manage::IncreaseRoom()//添加房间

{

    string type,Whether;

    double price;

    int number;

    cout<<"请输入房号: ";    cin>>number;

    cout<<"请输入房间类型: ";    cin>>type;

    cout<<"请输入价格: ";    cin>>price;

    cout<<"请输入房间状态: ";    cin>>Whether;

    WriteRoom(new Room(number,type,price,Whether));

}

void Manage::Check_In()//删除房间信息,即入房登记

{

    ReadData();

    SearchType();

    string name,intime,sex,type;

    int days,number;

    int id;

    cout<<"请输入房号: ";    cin>>number;

    cout<<"请输入顾客的姓名: "; cin>>name;

    cout<<"请输入顾客的身份证号: ";    cin>>id;

    cout<<"请输入顾客的性别: "; cin>>sex;

    cout<<"请输入入住日期: ";    cin>>intime;

    cout<<"请输入入住天数: "; cin>>days;

    for(i=0;i<Room_count;i++)

    {

        if(number==r[i]->InputNumber())

        {

            WriteGuest(new Guest(number,name,id,sex,intime,days));

            r[i]->SetWether("有");

            WriteData(1);

            cout<<"住房登记成功!"<<endl;

        }

     }

}

int Manage::Payment()//退房结账

{

    ReadData();

    Display(2);

    int number;

    cout<<"请输入房号: ";        cin>>number;

    for(i=0;i<Guest_count;i++)

    {

        if(number==g[i]->InputNumber())

        {

            return i;

        }

     }

}

void Manage::Check_Out()

{

    int x=Payment();

    ReadData();

    for(i=0;i<Room_count;i++)

    {

        if(g[x]->InputNumber()==r[i]->InputNumber())

        {

            r[i]->SetWether("无");

            cout<<"退房成功,您一共消费了 "<<g[x]->InputDays() *r[i]->InputPrice()<<" 元"<<endl;

            WriteData(1);

        }    

     }

    g[x]=NULL;

    WriteData(2);

}

void Manage::Display(int n)//浏览所有房间信息

{

    ReadData();

    switch(n){

    case 1:

        for(i=0; i<Room_count-1; i++)

        {

            cout<<"房号:"<<r[i]->InputNumber()<<"\t房间类型: "<<r[i]->InputType()<<"\t房间价格: "<<r[i]->InputPrice()<<"\t房间状态: "<<r[i]->InputWhether()<<endl<<endl;

        } break;

    case 2:

        for(i=0;i<Guest_count-1;i++)

        {

            cout<<"房间号: "<<g[i]->InputNumber()<<"\t顾客姓名: "<<g[i]->InputName()<<"\t身份证号: "<<g[i]->InputId()<<"\t顾客性别:"<<g[i]->InputSex()<<"\t入住时间: "<<g[i]->InputIntime()<<"\t入住天数: "<<g[i]->InputDays()<<endl<<endl;

        } break;

    }

}

void Manage::ReadData()

{

    fstream Rin,Gin;

    Rin.open("room.txt",ios::in);//打开文件

    if(!Rin)

    {

        cout<<"未找到room文件,请先建立文件!"<<endl;

        return;

    }

    Room_count=0;

    while(!Rin.eof()){

        string type,Whether;

        double price;

        int number;

        Rin>>number>>type>>price>>Whether;

        r[Room_count++]=new Room(number,type,price,Whether);

    }

    Rin.close();//关闭文件

    Gin.open("guest.txt",ios::in);

    if(!Gin)

    {

        cout<<"未找到guest文件,请先建立文件!"<<endl;

        return;    

    }

    Guest_count=0;

    while(!Gin.eof()){

        string name,intime,sex;

        int days,number;

        int id;

        Gin>>number>>name>>id>>sex>>intime>>days;

        g[Guest_count++]=new Guest(number,name,id,sex,intime,days);

    }

    Gin.close();

}

void Manage::WriteData(int n)

{

    switch(n)

    {

        case 1:

        {

        ofstream Rout("room.txt",ios::trunc); //用二进制的方法打开顾客文件 ,覆盖掉之前的所有信息重新写入

        for(i=0; i<Room_count-1; i++) //根据顾客数量判断输入几组信息

        {

            if(r[i]!=NULL)

            {

                WriteRoom(r[i]);//调用构造函数来创建顾客信息

            }

        }

        Rout.close(); break;}

        case 2:{

        ofstream Gout("guest.txt",ios::trunc); //用二进制的方法打开顾客文件 ,覆盖掉之前的所有信息重新写入

        for(i=0; i<Guest_count-1; i++) //根据顾客数量判断输入几组信息

        {

            if(g[i]!=NULL)

            {    

                WriteGuest(g[i]);//调用构造函数来创建顾客信息

            }

        }

        Gout.close();break;}

    }

}

void Manage::WriteRoom(Room *r)//储存单个信息

{

    ofstream Rout("room.txt",ios::app);//打开房间文件,追加读写,不会覆盖掉之前的所有信息

    Rout<<r->InputNumber()<<"\t"<<r->InputType()<<"\t"<<r->InputPrice()<<"\t"<<r->InputWhether()<<endl;

    Rout.close();

}

void Manage::WriteGuest(Guest *g)//储存单个信息

{

    ofstream Gout("guest.txt",ios::app);//打开顾客文件,追加读写,不会覆盖掉之前的所有信息

    Gout<<g->InputNumber()<<"\t"<<g->InputName()<<"\t"<<g->InputId()<<"\t"<<g->InputSex()<<"\t"<<g->InputIntime()<<"\t"<<g->InputDays()<<endl;

    Gout.close();

}

void Manage::SearchType()

{

    ReadData();

    for(i=0;i<Room_count;i++)

    {

        if(r[i]->InputWhether()=="无")

            {

            r[i]->show();}

        }    

}

void Manage::SearchNumber()

{

    ReadData();

    int number,n;

    cout<<"请输出要查询的房间号: "; cin>>number;

    for(i=0;i<Room_count-1;i++)

    {

        if(number==r[i]->InputNumber())

            r[i]->show();

        }

    for(i=0;i<Guest_count-1;i++)

    {

        if(g[i]->InputNumber()==number)

            g[i]->show();

        }    

}

int main()

{

    Manage M;

    int n;

    while(1)

    {

        system("cls");    

        cout<<endl<<endl<<endl<<"\t\t\t宾 馆 房 间 管 理 系 统     "<<endl<<endl;

        cout<<"\t\t\t1、房 间 信 息 的 录 入"<<endl<<endl;

        cout<<"\t\t\t2、顾 客 入 住 房 间 登 记"<<endl<<endl;

        cout<<"\t\t\t3、顾 客 退 房 结 账"<<endl<<endl;

        cout<<"\t\t\t4、所 有 房 间 信 息 显 示"<<endl<<endl;

        cout<<"\t\t\t5、所 有 顾 客 的 显 示"<<endl<<endl;

        cout<<"\t\t\t6、查 询 所 有 空 房 间"<<endl<<endl;

        cout<<"\t\t\t7、查 询 指 定 的 房 间 号"<<endl<<endl;

        cout<<"\t\t\t8、退 出 系 统"<<endl<<endl;

        cout<<endl<<"请选择:  ";

        cin>>n;

        cout<<endl<<endl;

        switch(n)

        {

            case 1:M.IncreaseRoom();getch();break;

            case 2:M.Check_In();getch();break;

            case 3:M.Check_Out();getch();break;

            case 4:M.Display(1);getch();break;

            case 5:M.Display(2);getch();break;

            case 6: M.SearchType();getch();break;

            case 7: M.SearchNumber();getch();break;    

            case 8:exit(0);    

        }         

    }

    return 0;

 }

6.用户使用说明

建立一个guest文本,选择要操作的序号,回车后直接输入。

  1. 测试结果

  • 3
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
抱歉,我不是一个代码搜索引擎,也不会提供完整的代码。但是,我可以给您提供一些思路和建议,以帮助您编写宾馆客房管理系统代码。 首先,您需要确定系统的功能和需求。宾馆客房管理系统通常包括以下功能: 1. 客房管理:包括客房信息维护、客房状态管理、客房预订、入住和退房管理等。 2. 顾客管理:包括顾客信息维护、订单管理、结算管理等。 3. 员工管理:包括员工信息维护、权限管理、工资管理等。 4. 统计报表:包括房间利用率、收入统计、客房入住率等。 在确定了系统的功能和需求后,您需要选择合适的编程语言和数据库。C++是一种强大的编程语言,但对于初学者来说可能有一定的难度。您可以选择其他易于学习的编程语言,例如Python等。至于数据库,则可以选择MySQL等免费的关系型数据库。 接下来,您需要设计系统的数据结构和算法。宾馆客房管理系统通常包括以下数据结构: 1. 房间类:用于存储客房信息,包括房间号、房间类型、房间状态等。 2. 顾客类:用于存储顾客的信息,包括姓名、证件号码、联系方式等。 3. 订单类:用于存储订单的信息,包括订单编号、订单状态、入住日期、离店日期等。 4. 员工类:用于存储员工的信息,包括姓名、工号、职位等。 在设计了数据结构后,您需要编写相应的算法实现系统的功能。例如,预订客房时,需要遍历客房列表,找到满足客户要求的客房,并将客房状态设置为已预订。 最后,您需要进行系统测试和调试,确保系统的稳定性和可靠性。同时,您还需要进行代码优化和注释,使代码更易于维护和扩展。 希望这些建议能够帮助您编写宾馆客房管理系统代码

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值