Linux下C++酒店管理系统
功能要求:

相关图片:
拆分版
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++酒店管理系统的更多相关文章
- Linux下部署开源版“禅道”项目管理系统《转载》
Linux下部署开源版“禅道”项目管理系统 https://www.cnblogs.com/xxsl/p/6525378.html
- Linux下发包处理
Linux下发包处理: 1.用top分析工具来查看哪个进程占用的CPU资源比较大 2. 通过命令来查看都是那些端口被占用了 netstat -antp | more 3.在top里面查看到的异 ...
- [转]Linux下的图形库介绍
[转]Linux 下的图形库介绍 http://blog.csdn.net/gogor/article/details/5925925 在进行Linux下的图形系统编程时,我们常常会遇到以下这些概念: ...
- 在Ubuntu Linux下怎样安装QQ
最近好多人在吐槽Linux下上QQ简直就是煎熬,网页版的不方便,网上各种版本的QQ要么是功能不全.要么是界面丑到爆,要么是运行不稳定.那么这次为大家带来一个功能完整.运行稳定的wineQQ安装过程. ...
- linux下Mysql 的安装、配置、数据导入导出
MySQL是一种开放源代码的关系型数据库管理系统(RDBMS),虽然功能未必很强大,但因它的免费开源而广受欢迎. 这次,接着上一篇<CentOs minimal安装和开发环境部署>,讲下L ...
- Linux下Tomcat catalina.out自动归档,以及logrotate 配置详解
Linux下Tomcat catalina.out自动归档 如果 catalina.out 日志达到 2GB 大小的时候,Tomcat 因为缓存问题,便没有办法继续输出日志了. 为了避免这种情况,你 ...
- Linux下python3、virtualenv、Mysql、redis安装配置
一.在Linux安装python解释器 1.下载python3源码包 cd /opt/ wget https://www.python.org/ftp/python/3.6.2/Python-3.6. ...
- Linux下LDAP统一认证解决方案
Linux下LDAP统一认证解决方案 --http://www.cangfengzhe.com/wangluoanquan/3.html 转自:http://www.cnblogs.com/MYSQL ...
- linux下硬盘的分区:
提到硬盘的分区,以前就是很乱,有什么主分区/扩展分区/逻辑分区等;它们有什么区别呢?现在简单的了解一下: 由于在MBR的主引导记录中的分区表里面最多只能记录4个分区记录,这个不够用啊,为了解决这个问题 ...
随机推荐
- 鸿蒙OS还有机会吗?
鸿蒙最初的定位是手机操作系统,那在市场已饱和.生态已成熟,Android地位已牢不可破的当下,能成功是小概率事件,就像PC时代无法撼动Windows地位一样. 好在鸿蒙调整定位定义为面向未来的IOT操 ...
- 第02组 Alpha冲刺(1/4)
队名:十一个憨批 组长博客 作业博客 组长黄智 过去两天完成的任务:进行组员分工 GitHub签入记录 接下来的计划:构思游戏实现 还剩下哪些任务:敲代码 燃尽图 遇到的困难:任务分配的不及时,导致很 ...
- 理解 IO_WAIT 并且了解利用包括 top htop iotop iostat 工具来查看 IO 性能
今天继续拜读「深入浅出计算机组成原理」专栏,觉得讲 IO_WAIT 这篇很有意思,正好可以结合前面的一篇讲物理硬件存速度的一块儿看. 现在我们看硬盘厂商出品的性能报告,通常会看到两个指标,一个是响应时 ...
- python range 和xrange
对于这两个好像功能都差不多,这两个经常会被搞混,所以今天一定要把这个完全弄清楚. 首先我们看看range: range([start,] stop[, step]),根据start与stop指定的范围 ...
- JMeter的基本使用
什么是Jmeter JMeter是Apache基于Java开发的压力测试工具,通俗的说,你想知道你的接口有多猛,你的服务器是否耐揍,这个家伙可以用数据告诉你.原来学过JMeter的基本使用,发现想不起 ...
- 解决linux环境下nohup: redirecting stderr to stdout问题
在生产环境下启动Weblogic时,发现原来好好的nohup信息输出到指定文件中的功能,突然出问题了.现象是控制台输出的信息一部分输出到了我指定的文件,另一部分却输出到了nohup.out,而我是不想 ...
- SSM 实现支付宝支付功能(图文详解+完整代码)
阅读本文大概需要 4 分钟. 前言 本教程详细介绍了如何使用ssm框架实现支付宝支付功能.本文章分为两大部分,分别是「支付宝测试环境代码测试」和「将支付宝支付整合到ssm框架」,详细的代码和图文解释, ...
- [Web 测试] Jest单元测试的几个指标
三个参数代表什么? %stmts是语句覆盖率(statement coverage):是不是每个语句都执行了? %Branch分支覆盖率(branch coverage):是不是每个if代码块都执行了 ...
- iis php web.config处理404,500等,跳转友好页面,显示500错误信息
显示500错误信息<pre name="code" class="html"><?xml version="1.0" en ...
- mysqldump 备份数据库脚本
创建备份数据库脚本mysql_backup.sh,内容如下: #!/bin/bash export PATH=/bin:/usr/bin:/usr/local/bin TODAY=`date +&qu ...