C++实现宾馆房间管理系统

本文实例为大家分享了C++实现宾馆房间管理系统的具体代码,供大家参考,具体内容如下

一、问题描述

设计一个程序实现对宾馆房间的基本管理,可以实现:客房信息的录入功能;客人入住登记、客人退房结算;客房信息浏览功能,浏览全部客户的信息,客房信息和客户信息分别保存于不同文件;客房信息查询,查询空房间情况,实现按房间号查询等。

二、基本要求

(1)使用面向对象编程思想编写开发过程中需要用到的类,比如:至少包含四个类:日期类,客房类,主要包含客房信息(房号类型,是否有客人等)及相关操作;客人类,主要完 成客户信息(身份证,入住时间,姓名,性别等)的相关操作;管理类实现对客房的管理。
(2)输入和输出可以使用文本文件重定向输入(保存数据为磁盘文件);也可以使用标准输入输出进行(提交时需要提交TXT格式输入数据)。比如:room.txt 的文件,文件中应包含 20 条以上记录(房间的初始状态),guest.txt 的文本文件,包含 10 条以上客人记录。 在运行程序时自动载入。
(3)基本功能要求具有增、删、改、查。

基本流程图

C++实现宾馆房间管理系统_第1张图片

#include
#include
#include
#include
#include 
#include
#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<<"房号:  "<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<<"顾客姓名:  "<>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;iInputNumber())
        {
            WriteGuest(new Guest(number,name,id,sex,intime,days));
            r[i]->SetWether("有");
            WriteData(1);
            cout<<"住房登记成功!"<>number;
    for(i=0;iInputNumber())
        {
            return i;
        }
     } 
} 
void Manage::Check_Out()
{
    int x=Payment();
    ReadData();
    for(i=0;iInputNumber()==r[i]->InputNumber())
        {
            r[i]->SetWether("无");
            cout<<"退房成功,您一共消费了 "<InputDays() *r[i]->InputPrice()<<" 元"<InputNumber()<<"\t房间类型: "<InputType()<<"\t房间价格: "<InputPrice()<<"\t房间状态: "<InputWhether()<InputNumber()<<"\t顾客姓名: "<InputName()<<"\t身份证号: "<InputId()<<"\t顾客性别:"<InputSex()<<"\t入住时间: "<InputIntime()<<"\t入住天数: "<InputDays()<>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文件,请先建立文件!"<>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; iInputNumber()<<"\t"<InputType()<<"\t"<InputPrice()<<"\t"<InputWhether()<InputNumber()<<"\t"<InputName()<<"\t"<InputId()<<"\t"<InputSex()<<"\t"<InputIntime()<<"\t"<InputDays()<InputWhether()=="无")
            { 
            r[i]->show();}
        }    
}
void Manage::SearchNumber()
{
    ReadData();
    int number,n;
    cout<<"请输出要查询的房间号: "; cin>>number;
    for(i=0;iInputNumber())
            r[i]->show();
        }
    for(i=0;iInputNumber()==number)
            g[i]->show();
        }    
}
int main()
{
    Manage M;
    int n;
    while(1)
    {
        system("cls");    
        cout<>n; 
        cout< 
 

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

你可能感兴趣的:(C++实现宾馆房间管理系统)