酒店管理系统c++代码
时间: 2024-04-07 12:27:07 浏览: 80
酒店管理系统是一个用于管理酒店业务的软件系统,它可以实现客房管理、预订管理、入住管理、退房管理等功能。下面是一个简单的酒店管理系统的C++代码示例:
```cpp
#include <iostream>
#include <string>
using namespace std;
class Room {
private:
int roomNumber;
string guestName;
bool isOccupied;
public:
Room(int number) {
roomNumber = number;
isOccupied = false;
}
void checkIn(string name) {
if (isOccupied) {
cout << "该房间已被占用!" << endl;
} else {
guestName = name;
isOccupied = true;
cout << "入住成功!" << endl;
}
}
void checkOut() {
if (isOccupied) {
guestName = "";
isOccupied = false;
cout << "退房成功!" << endl;
} else {
cout << "该房间未被占用!" << endl;
}
}
void displayStatus() {
cout << "房间号:" << roomNumber << endl;
if (isOccupied) {
cout << "客人姓名:" << guestName << endl;
} else {
cout << "该房间未被占用!" << endl;
}
}
};
int main() {
Room rooms[10] = {Room(101), Room(102), Room(103), Room(104), Room(105),
Room(201), Room(202), Room(203), Room(204), Room(205)};
int choice;
string name;
int roomIndex;
while (true) {
cout << "欢迎使用酒店管理系统!" << endl;
cout << "1. 入住" << endl;
cout << "2. 退房" << endl;
cout << "3. 查看房间状态" << endl;
cout << "0. 退出系统" << endl;
cout << "请输入您的选择:";
cin >> choice;
switch (choice) {
case 1:
cout << "请输入您的姓名:";
cin >> name;
cout << "请输入您要入住的房间号:";
cin >> roomIndex;
rooms[roomIndex - 1].checkIn(name);
break;
case 2:
cout << "请输入您要退房的房间号:";
cin >> roomIndex;
rooms[roomIndex - 1].checkOut();
break;
case 3:
cout << "请输入您要查看的房间号:";
cin >> roomIndex;
rooms[roomIndex - 1].displayStatus();
break;
case 0:
cout << "感谢使用酒店管理系统,再见!" << endl;
return 0;
default:
cout << "无效的选择,请重新输入!" << endl;
break;
}
}
return 0;
}
```
这段代码实现了一个简单的酒店管理系统,包括了入住、退房和查看房间状态等功能。用户可以根据提示进行相应的操作。
阅读全文