功能要求:

相关源码:码云:传送门,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. kuma 学习一 minikube 安装

    官方文档提供了比较全的环境安装说明 我使用的系统是mac,同时使用minikube 运行 安装kumactl 下载地址: https://kong.bintray.com/kuma/kuma-0.1. ...

  2. P4211 [LNOI2014]LCA LCT

    P4211 [LNOI2014]LCA 链接 loj luogu 思路 多次询问\(\sum\limits_{l \leq i \leq r}dep[LCA(i,z)]\) 可以转化成l到r上的点到根 ...

  3. NOI2019 Day2游记

    开场T1是个最短路优化建图,边向二维矩形内所有点连,本来可以写树套树的,但是卡空间(128MB),后来发现其实是不用把边都建出来的,只需要用数据结构模拟dijkstra的过程,支持二维区间对一个值取m ...

  4. FDQuery Out of memory

    4万行记录 FDQuery查询 Out of memory sql server 可以查询成功 First chance exception at $7505D722. Exception class ...

  5. HGNC数据库 HUGO基因命名委员会

    http://www.genenames.org/ HGNC 全称为HUGO Gene Nomenclature Committee, 叫做 HUGO基因命名委员会,负责对人类基因组上包括蛋白编码基因 ...

  6. ansible-playbook--jia使用

    #cat jia.yml - hosts: test-gfs user: dev gather_facts: true vars: PORT: "3306" MESAGE: &qu ...

  7. 【转】vim复制与粘贴

    用vim写代码时,经常遇到这样的场景,复制多行,然后粘贴. 这样做:1. 将光标移动到要复制的文本开始的地方,按v进入可视模式.2. 将光标移动到要复制的文本的结束的地方,按y复制.此时vim会自动将 ...

  8. 【Gamma】Scrum Meeting 4

    目录 写在前面 进度情况 任务进度表 Gamma阶段燃尽图 照片 写在前面 例会时间:5.31 22:30-23:00 例会地点:微信群语音通话 代码进度记录github在这里 临近期末,团队成员课程 ...

  9. leetcode 688. “马”在棋盘上的概率

    题目描述: 已知一个 NxN 的国际象棋棋盘,棋盘的行号和列号都是从 0 开始.即最左上角的格子记为 (0, 0),最右下角的记为 (N-1, N-1). 现有一个 “马”(也译作 “骑士”)位于 ( ...

  10. Mac OSX下增加TCP连接数

    查看 max files: $ sysctl -a | grep files kern.maxfiles = 12288 kern.maxfilesperproc = 10240 修改: $ sudo ...