功能要求:

相关源码:码云:传送门,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

最新文章

  1. XtraBackup出现 Can't connect to local MySQL server through socket '/tmp/mysql.sock'
  2. EasyUI-datagrid 对于展示数据进行处理(formatter)
  3. FFMpeg ver 20160213-git-588e2e3 滤镜中英文对照
  4. animate.css总结
  5. excel复制+粘贴,怎样让公式里的参数不自动变化?
  6. Action的搭建及application、request、Session的运用 多种方法
  7. IE9下Coolite.Ext出现createContextualFragment错误
  8. Log4j之properties配置文件详解
  9. 你不知道的Eclipse的用法:使用MAT分析Android的内存
  10. jsp内部传参与重定向传参
  11. mysql本地訪问linuxserver,出现SQLSTATE[HY000] [1130] Host &amp;#39;127.0.0.1&amp;#39; is not allowed to connect to this
  12. spring mvc对静态资源的访问
  13. Fiddler抓包工具证书安装
  14. [RHEL 6]GPT分区--parted
  15. OO第一次博客
  16. 【原创】关于Git暂存区的理解
  17. MyEclipse&#160;TestNG插件安装与配置
  18. beego 初体验 - 基础模块 - config, httplibs, logs
  19. xtrabackup备份mysql-3 差异备份
  20. 使用docker exec命令

热门文章

  1. 工作拾记 - 关于easyui模板后台改为vue-element
  2. js中的逗号运算符
  3. markdown转html
  4. discuz插件开发
  5. Android Studio 之 LiveData 的配合使用,底层数据变化,自动通知界面
  6. 【译文】走出Java ClassLoader迷宫 Find a way out of the ClassLoader maze
  7. Tocmat 统计tomcat进程内的线程数
  8. APP测试要点整理
  9. MLflow系列2:MLflow追踪
  10. Linux权限:提示-bash: ./startup.sh: Permission denied的解决方案