用c++语言写一个宾馆房间管理系统 设计一个程序实现对宾馆房间的基本管理,可以实现:客房信息的录入功能;客人入住登记、 客人退房结算;客房信息浏览功能,浏览全部客户的信息,客房信息和客户信息分别保存于 不同文件;客房信息查询,查询空房间情况,实现按房间号查询
时间: 2024-02-25 07:59:22 浏览: 48
好的,我会根据您的要求来回答您的问题。
关于宾馆房间管理系统的设计,大致思路如下:
1. 客房信息的录入功能
可以通过用户输入来录入客房信息,包括房间号、房间类型、房间价格等信息,将这些信息保存到一个文件中,每一行代表一个房间的信息。
2. 客人入住登记、客人退房结算
当客人入住时,可以通过输入客人的姓名、身份证号等信息来登记客人信息,并将房间状态改为“已入住”。当客人退房时,可以查询客人信息,计算费用并结算,同时将房间状态改为“空闲”。
3. 客房信息浏览功能
可以通过读取保存客房信息的文件来实现客房信息浏览功能,将每个房间的信息输出到屏幕上。
4. 客房信息查询
可以实现按照房间号查询客房信息的功能,通过读取保存客房信息的文件,查找对应的房间信息并输出到屏幕上。
具体实现时,可以采用面向对象的思路,设计一个Room类和一个Guest类,分别表示客房和客人的信息。然后再设计一个Hotel类,实现宾馆房间管理系统的各个功能。
以下是一个简单的示例代码:
```c++
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
using namespace std;
// 客房类
class Room {
public:
Room(int no, string type, double price, bool is_empty) {
this->no = no;
this->type = type;
this->price = price;
this->is_empty = is_empty;
}
int no; // 房间号
string type; // 房间类型
double price; // 房间价格
bool is_empty; // 房间是否空闲
};
// 客人类
class Guest {
public:
Guest(string name, string id) {
this->name = name;
this->id = id;
}
string name; // 客人姓名
string id; // 客人身份证号
};
// 宾馆类
class Hotel {
public:
// 构造函数,从文件中读取客房信息
Hotel(string filename) {
ifstream fin(filename);
int no;
string type;
double price;
bool is_empty;
while (fin >> no >> type >> price >> is_empty) {
Room room(no, type, price, is_empty);
rooms.push_back(room);
}
fin.close();
}
// 显示客房信息
void display_rooms() {
for (int i = 0; i < rooms.size(); i++) {
cout << "房间号:" << rooms[i].no << endl;
cout << "房间类型:" << rooms[i].type << endl;
cout << "房间价格:" << rooms[i].price << endl;
cout << "房间状态:" << (rooms[i].is_empty ? "空闲" : "已入住") << endl;
cout << endl;
}
}
// 查询空房间
void query_empty_rooms() {
for (int i = 0; i < rooms.size(); i++) {
if (rooms[i].is_empty) {
cout << "空房间号:" << rooms[i].no << endl;
}
}
}
// 登记客人信息
void check_in(string name, string id, int room_no) {
for (int i = 0; i < rooms.size(); i++) {
if (rooms[i].no == room_no) {
rooms[i].is_empty = false;
Guest guest(name, id);
guests.push_back(guest);
cout << "登记成功!" << endl;
return;
}
}
cout << "房间不存在!" << endl;
}
// 结算退房
void check_out(int room_no) {
for (int i = 0; i < rooms.size(); i++) {
if (rooms[i].no == room_no) {
rooms[i].is_empty = true;
double price = rooms[i].price;
for (int j = 0; j < guests.size(); j++) {
if (guests[j].name == rooms[i].type) {
price *= 0.8;
break;
}
}
cout << "结算成功!费用为:" << price << endl;
return;
}
}
cout << "房间不存在!" << endl;
}
// 保存客房信息到文件
void save_rooms(string filename) {
ofstream fout(filename);
for (int i = 0; i < rooms.size(); i++) {
fout << rooms[i].no << " " << rooms[i].type << " " << rooms[i].price << " " << rooms[i].is_empty << endl;
}
fout.close();
}
private:
vector<Room> rooms; // 客房信息
vector<Guest> guests; // 客人信息
};
// 主函数
int main() {
Hotel hotel("rooms.txt");
int choice;
while (true) {
cout << "请选择操作:" << endl;
cout << "1. 客房信息浏览" << endl;
cout << "2. 查询空房间" << endl;
cout << "3. 客人入住登记" << endl;
cout << "4. 客人退房结算" << endl;
cout << "5. 保存客房信息" << endl;
cout << "6. 退出" << endl;
cin >> choice;
switch (choice) {
case 1:
hotel.display_rooms();
break;
case 2:
hotel.query_empty_rooms();
break;
case 3:
string name, id;
int room_no;
cout << "请输入客人姓名:";
cin >> name;
cout << "请输入客人身份证号:";
cin >> id;
cout << "请输入房间号:";
cin >> room_no;
hotel.check_in(name, id, room_no);
break;
case 4:
cout << "请输入房间号:";
cin >> room_no;
hotel.check_out(room_no);
break;
case 5:
hotel.save_rooms("rooms.txt");
cout << "保存成功!" << endl;
break;
case 6:
return 0;
default:
cout << "无效操作!" << endl;
break;
}
}
return 0;
}
```
以上代码只是一个简单的示例,实际应用中可能需要更多的功能和优化。