功能要求:

相关源码:码云:传送门,GitHub:传送门

相关图片:

拆分版

make编译

./hotel运行

输入2,进入开房模块

相关源码:

class.cpp

 #include <fstream>
#include "tools.h"
#include "class.h" using namespace std; Customer* cust[];
Room* room[]; int live; // 被订房间数 // 获取room_num
short Room::get_room_num(void)
{
return room_num;
} // 返回房间的下标
int Manage::room_index(short room_num)
{
short num = room_num;
for(int i=; i<; i++)
{
if(num == room[i]->get_room_num())
{
return i;
}
}
return -;
} // 返回顾客的下标
int Manage::cust_index(short room_num)
{
short num = room_num;
for(int i=; i<; i++)
{
if(num == cust[i]->room_num)
{
return i;
}
}
return -;
} // 查询剩余房间
void Manage::find_room(void)
{
for(int i=; i<; i++)
{
if(i == || i == )
{
cout << endl;
}
if(room[i]->use != )
{
continue;
}
cout << room[i]->room_num << " ";
}
cout << endl;
} // 开房
void Manage::get_room(void)
{
cout << "现有房间如下" << endl;
find_room(); // cout << "已经入住的人员" << endl;
// show_cust(); cout << "请输入您选择的房间:";
short room_num;
cin >> room_num;
int flag = used(room_num);
if(flag == )
{
cout << "此房间不能使用,请重新选择" << endl;
getch();
return;
}
else if(flag == -)
{
cout << "此房间不存在,请重新选择" << endl;
getch();
return;
}
else
{
cout << "您选择的房间是:" << room_num << endl;
} int index = room_index(room_num);
short type = room[index]->room_type; cout << "请输入您的姓名:";
string name;
cin >> name;
cout << "请输入您的身份证:";
string id;
cin >> id;
cout << "请输入您的2位家属(0,表示没有)" << endl;
string family1,family2;
cin >> family1 >> family2; if(type == )
{
if(family1 != "" || family2 != "")
{
cout << "人数过多,开房失败" << endl;
getch();
return;
}
}
else if(type == )
{
if(family1 != "" && family2 != "")
{
cout << "人数过多,开房失败" << endl;
getch();
return;
}
}
else
{
} cout << "请输入要订的天数:";
short day;
cin >> day;
short pay = day*room[index]->price;
cout << "请支付" << pay << "元" << endl;
short money = ,change = ;
cout << "收您:";
cin >> money;
cout << "元" << endl;
change = money-pay;
if(change < )
{
cout << "余额不足,请充值" << endl;
getch();
return;
}
cout << "找您" << change << "元" << endl; short floor = room_num/; cust[live++] = new Customer(name,id,family1,family2,floor,room_num,day); cout << "已订房间:" << live << endl; for(int i=; i<; i++)
{
if(room[i]->room_num == room_num)
{
room[i]->use = ;
}
} cout << "开房成功,欢迎您的入住,祝你生活愉快!" << endl;
getch();
} // 使用情况
int Manage::used(short room_num)
{
short num = room_num;
for(int i=; i<; i++)
{
if(num == room[i]->room_num)
{
if(room[i]->use == )
{
return ;
}
else
{
return ;
}
}
}
return -;
} // 显示顾客
void Manage::show_cust(void)
{
for(int i=; i<; i++)
{
if(cust[i]->name == "")
{
break;
}
else
{
cout << "姓名:" << cust[i]->name << "," << "房间:" << cust[i]->room_num << ","; string f1,f2;
f1 = cust[i]->family1;
f2 = cust[i]->family2;
cout << "家属1:";
if(f1 == "") cout << " ,";
else cout << f1 << ",";
cout << "家属2:";
if(f2 == "") cout << " ";
else cout << f2;
}
}
} // 房间价格
int Manage::room_price(short room_num)
{
short num = room_num;
for(int i=; i<; i++)
{
if(room[i]->room_num == num)
{
return room[i]->price;
}
}
return ;
} // 续费
void Manage::renew_room(void)
{
cout << "请输入你的房间号:";
short room_num;
cin >> room_num;
int flag = used(room_num);
if(flag == - || flag == )
{
cout << "您输入的房间号有误" << endl;
getch();
return;
} int index = cust_index(room_num); cout << "您的房间剩余:" << cust[index]->day << "天" << endl; cout << "请输入你要续的天数:";
short day;
cin >> day;
short pay = day*room_price(room_num);
cout << "请支付" << pay << "元" << endl;
short price = ,change = ;
cin >> price;
change = price-pay;
if(change < )
{
cout << "余额不足,请充值" << endl;
getch();
return;
}
cout << "收您" << price <<"元,找您" << change << "元" << endl; string rename = cust[index]->name,reid = cust[index]->id;
string refamily1=cust[index]->family1,refamily2=cust[index]->family2;
short refloor = cust[index]->floor,reday = cust[index]->day+day;
cust[index] = new Customer(rename,reid,refamily1,refamily2,refloor,room_num,reday); cout << "续费成功,房间的使用时间为:" << reday <<"天" << endl;
getch(); } // 退房
void Manage::cancel_room(void)
{
cout << "请输入您的房间号:";
short room_num;
string name;
cin >> room_num;
cout << "请输入您的姓名:";
cin >> name;
int flag = used(room_num);
if(flag == || flag == -)
{
cout << "您输入的房间有误。" << endl;
getch();
return;
}
else
{
short refloor = ,retype = ,reprice = ; int i = cust_index(room_num);
if(i != -)
{
if(cust[i]->name == name)
{
short price = room[room_index(room_num)]->price;
short change = cust[i]->day*price;
cout << "退还您" << change << "元" << endl; cust[i] = new Customer("","","","",,,);
int j = room_index(room_num);
refloor = room[j]->floor;
retype = room[j]->room_type;
reprice = room[j]->price;
room[j] = new Room(refloor,room_num,retype,reprice,); cout << "退房成功,感谢您的光顾,欢迎下次光临!"<< endl;
live--;
getch();
return;
}
else
{
//cout << cust[i]->name << endl;
cout << "您输入的相关信息有误" << endl;
getch();
return;
}
}
else
{
cout << "您输入的信息有误" << endl;
getch();
return;
}
}
} // 顾客初始化
void Manage::c_init(void)
{
fstream ci("data/cust.txt",ios::in);
if(!ci.good())
{
cout << "cust.txt数据加载异常" << endl;
} for(int i=; i<; i++)
{
string name,id,family1,family2;
short floor,room_num,day;
ci >> name >> id >> family1 >> family2;
ci >> floor >> room_num >> day;
cust[i] = new Customer(name,id,family1,family2,floor,room_num,day);
if(name != "")
{
live++;
}
}
} // 房间初始化
void Manage::r_init(void)
{
live = ;
fstream ri("data/room.txt",ios::in);
if(!ri.good())
{
cout << "room.txt数据加载异常" << endl;
} for(int i=; i<; i++)
{
short floor,room_num,room_type,price,use;
ri >> floor >> room_num;
ri >> room_type >> price >> use;
room[i] = new Room(floor,room_num,room_type,price,use);
}
} // 数据保存
void Manage::save_data(void)
{
fstream co("data/cust.txt",ios::out);
fstream ro("data/room.txt",ios::out); for(int i=; i<; i++)
{
co << cust[i]->name << " " << cust[i]->id << " ";
co << cust[i]->family1 << " " << cust[i]->family2 << " ";
co << cust[i]->floor << " " << cust[i]->room_num << " ";
co << cust[i]->day << "\n"; ro << room[i]->floor << " " << room[i]->room_num << " ";
ro << room[i]->room_type << " " << room[i]->price << " ";
ro << room[i]->use << "\n";
}
} // 菜单
void Manage::menu(void)
{
cout << "***欢迎使用酒店管理系统***" << endl;
cout << " 1、查询房间" << endl;
cout << " 2、开房" << endl;
cout << " 3、续费" << endl;
cout << " 4、退房" << endl;
cout << " 0、退出系统" << endl;
cout << "-----------------------" << endl;
}

main.cpp

 #include <iostream>
#include <fstream>
#include <stdlib.h>
#include <termio.h>
#include "class.h"
#include "tools.h" using namespace std; Manage admin; // 主函数
int main()
{
admin.c_init();
admin.r_init();
while()
{
system("clear");
admin.menu();
switch(get_cmd('',''))
{
case '': admin.find_room(); break;
case '': admin.get_room(); break;
case '': admin.renew_room(); break;
case '': admin.cancel_room(); break;
case '': admin.save_data(); return ;
}
getch();
} }

tools.cpp

 #include "tools.h"
#include <string.h>
#include <getch.h>
#include <stdbool.h> void clear_stdin(void)
{
stdin->_IO_read_ptr = stdin->_IO_read_end;//清理输入缓冲区
} char get_cmd(char start,char end)
{
clear_stdin(); printf("请输入指令:");
while(true)
{
char val = getch();
if(val >= start && val <= end)
{
printf("%c\n",val);
return val;
}
}
}

class.h

 #ifndef CLASS_H
#define CLASS_H #include <iostream>
#include <string.h> using namespace std; class Customer
{
public:
string name; //姓名
string id; //身份证
string family1; //家属1
string family2; //家属2
short floor; //楼层
short room_num; //房间号
short day; //时间
Customer(string name="",string id="",string family1="",string family2="",short floor=,short room_num=,short day=)
{
this->name = name;
this->id = id;
this->family1 = family1;
this->family2 = family2;
this->floor = floor;
this->room_num = room_num;
this->day = day;
}
}; class Room
{
public:
short floor; //楼层
short room_num; //房间号
short room_type; //房间类型
short price; //价格
short use; //是否使用
Room(short floor=,short room_num=,short room_type=,short price=,short use=)
{
this->floor = floor;
this->room_num = room_num;
this->room_type = room_type;
this->price = price;
this->use = use;
}
short get_room_num(void); }; class Manage
{
public:
void menu(void); // 菜单
void find_room(void); // 剩余房间
void get_room(void); // 开房
void renew_room(void); // 续费
void cancel_room(void); // 退房
int room_index(short room_num); // 房间下标
int cust_index(short room_num); // 顾客下标
int used(short room_num); // 房间使用情况
void show_cust(void); // 显示入住顾客
int room_price(short room_num); // 房间价格
void c_init(void); // 顾客初始化
void r_init(void); // 房间初始化
void save_data(void); // 保存数据
}; #endif//CLASS_H

tools.h

 #ifndef TOOL_H
#define TOOL_H #include <stdio.h> #include "tools.h"
#include <string.h>
#include <getch.h>
#include <stdbool.h> void clear_stdin(void); char get_cmd(char start,char end); #endif//TOOL_h

Linux下C++酒店管理系统的更多相关文章

  1. Linux下部署开源版“禅道”项目管理系统《转载》

    Linux下部署开源版“禅道”项目管理系统 https://www.cnblogs.com/xxsl/p/6525378.html

  2. Linux下发包处理

    Linux下发包处理: 1.用top分析工具来查看哪个进程占用的CPU资源比较大  2. 通过命令来查看都是那些端口被占用了   netstat -antp | more  3.在top里面查看到的异 ...

  3. [转]Linux下的图形库介绍

    [转]Linux 下的图形库介绍 http://blog.csdn.net/gogor/article/details/5925925 在进行Linux下的图形系统编程时,我们常常会遇到以下这些概念: ...

  4. 在Ubuntu Linux下怎样安装QQ

    最近好多人在吐槽Linux下上QQ简直就是煎熬,网页版的不方便,网上各种版本的QQ要么是功能不全.要么是界面丑到爆,要么是运行不稳定.那么这次为大家带来一个功能完整.运行稳定的wineQQ安装过程. ...

  5. linux下Mysql 的安装、配置、数据导入导出

    MySQL是一种开放源代码的关系型数据库管理系统(RDBMS),虽然功能未必很强大,但因它的免费开源而广受欢迎. 这次,接着上一篇<CentOs minimal安装和开发环境部署>,讲下L ...

  6. Linux下Tomcat catalina.out自动归档,以及logrotate 配置详解

    Linux下Tomcat catalina.out自动归档 如果 catalina.out 日志达到 2GB 大小的时候,Tomcat 因为缓存问题,便没有办法继续输出日志了.  为了避免这种情况,你 ...

  7. Linux下python3、virtualenv、Mysql、redis安装配置

    一.在Linux安装python解释器 1.下载python3源码包 cd /opt/ wget https://www.python.org/ftp/python/3.6.2/Python-3.6. ...

  8. Linux下LDAP统一认证解决方案

    Linux下LDAP统一认证解决方案 --http://www.cangfengzhe.com/wangluoanquan/3.html 转自:http://www.cnblogs.com/MYSQL ...

  9. linux下硬盘的分区:

    提到硬盘的分区,以前就是很乱,有什么主分区/扩展分区/逻辑分区等;它们有什么区别呢?现在简单的了解一下: 由于在MBR的主引导记录中的分区表里面最多只能记录4个分区记录,这个不够用啊,为了解决这个问题 ...

随机推荐

  1. mysql初始

    数据(data) : -描述事物的符号记录称为数据,符号既可以是数据,文字,图片,声音,语言等,符号都可以经过数字化后存入计算机中 - 计算机中描述一个事物,就需要抽取这一事物的典型特征,组成一条记录 ...

  2. exception The absolute uri: [http://java.sun.com/jsp/jstl/core] cannot be resolved in either web.xml or the jar files deployed with this application

        1.情景展示 eclipse,运行web项目时,报错信息如下: The absolute uri: [http://java.sun.com/jsp/jstl/core] cannot be ...

  3. 20175211 《实验三 敏捷开发与XP实践》实验报告

    目录 一.实验内容 二.实验步骤 四.实验过程中遇到的问题及其解决方法 五.心得体会 六.码云链接 七.结对成员链接 八.参考资料 一.实验内容 (1)编码标准 (2)Git的使用 (3)重构 (4) ...

  4. Django实现自动发布(2视图-服务管理)

    通常页面要能对资源进行增删改查,对应http的 POST.DELETE.UPDATE.GET 页面显示使用了layui,而layui的表格有自己的数据获取方式,所以我们的视图要做一些调整,不使用后端渲 ...

  5. Python导入 from lxml import etree 导入不了

    问题在学爬虫,Python 版本是2.7,安装的lxml包是4.3的,在 from lxml import etree 时发现一直报错,网上查询,原来是Python版本和lxml包版本不一致导致的. ...

  6. .Net Core 发送https请求/.net core 调用数字证书 使用X509Certificate2

    .Net Core 发送https请求 .net core 调用数字证书 使用X509Certificate2 .NET下面的 .netfromwork使用和asp.net core下使用方式不一样 ...

  7. mac jq for json format

    mac jq #1.安装 brew install jq #2.创建文件 echo '{"name": "Ruby"}' > ./test.json #3 ...

  8. mysql 8.0.18 hash join测试(内外网首文)

    CREATE TABLE COLUMNS_hj as select * from information_schema.`COLUMNS`; INSERT INTO COLUMNS_hj SELECT ...

  9. 虚拟机 /dev/mapper/centos-root 动态扩容

    [root@bogon ~]# df -h Filesystem Size Used Avail Use% Mounted on .2G .2G 51M % / devtmpfs 908M 908M ...

  10. Django入门2开发工具pycharm的配置

    在pycharm中新建django项目 查看django是否安装成功 运行django 设置pycharm快捷键 设置python模板,新建的python文件就会自动生成一些信息 设置django启动 ...