用单链表实现宾馆客房管理系统中计算各类客房收入情况,按楼层统计没有入住的客房数 源代码
时间: 2024-03-21 22:43:46 浏览: 181
以下是用单链表实现宾馆客房管理系统中计算各类客房收入情况,按楼层统计没有入住的客房数的示例代码(C++实现):
```c++
#include <iostream>
using namespace std;
// 客房类型
enum RoomType {
SINGLE_ROOM = 1,
STANDARD_ROOM,
DELUXE_ROOM,
PRESIDENTIAL_ROOM
};
// 客房信息
struct Room {
int number; // 客房号
RoomType type; // 客房类型
bool isOccupied; // 是否入住
int daysOccupied; // 入住天数
double price; // 客房单价
};
// 节点
struct Node {
Room data; // 数据域
Node* next; // 指针域
};
// 客房链表
class RoomList {
public:
// 构造函数
RoomList() {
head = new Node();
head->next = nullptr;
}
// 添加客房
void addRoom(Room room) {
Node* p = head;
while (p->next != nullptr) {
p = p->next;
}
Node* newNode = new Node();
newNode->data = room;
newNode->next = nullptr;
p->next = newNode;
}
// 计算各类客房收入情况
double calculateIncome(RoomType type) {
double totalIncome = 0.0;
Node* p = head->next;
while (p != nullptr) {
if (p->data.type == type && p->data.isOccupied) {
totalIncome += p->data.price * p->data.daysOccupied;
}
p = p->next;
}
return totalIncome;
}
// 按楼层统计没有入住的客房数
int countUnoccupiedRooms(int floor) {
int count = 0;
Node* p = head->next;
while (p != nullptr) {
if (p->data.number / 100 == floor && !p->data.isOccupied) {
count++;
}
p = p->next;
}
return count;
}
private:
Node* head; // 头指针
};
int main() {
// 初始化客房链表
RoomList roomList;
roomList.addRoom({101, SINGLE_ROOM, true, 3, 300.0});
roomList.addRoom({102, SINGLE_ROOM, true, 2, 300.0});
roomList.addRoom({103, SINGLE_ROOM, false, 0, 300.0});
roomList.addRoom({201, STANDARD_ROOM, true, 4, 450.0});
roomList.addRoom({202, STANDARD_ROOM, false, 0, 450.0});
roomList.addRoom({203, STANDARD_ROOM, false, 0, 450.0});
roomList.addRoom({301, DELUXE_ROOM, true, 5, 600.0});
roomList.addRoom({302, DELUXE_ROOM, true, 1, 600.0});
roomList.addRoom({303, DELUXE_ROOM, false, 0, 600.0});
roomList.addRoom({401, PRESIDENTIAL_ROOM, false, 0, 1500.0});
roomList.addRoom({402, PRESIDENTIAL_ROOM, false, 0, 1500.0});
roomList.addRoom({403, PRESIDENTIAL_ROOM, false, 0, 1500.0});
// 计算各类客房收入情况
cout << "Single Room Income: " << roomList.calculateIncome(SINGLE_ROOM) << endl;
cout << "Standard Room Income: " << roomList.calculateIncome(STANDARD_ROOM) << endl;
cout << "Deluxe Room Income: " << roomList.calculateIncome(DELUXE_ROOM) << endl;
cout << "Presidential Room Income: " << roomList.calculateIncome(PRESIDENTIAL_ROOM) << endl;
// 按楼层统计没有入住的客房数
cout << "Unoccupied Rooms on Floor 1: " << roomList.countUnoccupiedRooms(1) << endl;
cout << "Unoccupied Rooms on Floor 2: " << roomList.countUnoccupiedRooms(2) << endl;
cout << "Unoccupied Rooms on Floor 3: " << roomList.countUnoccupiedRooms(3) << endl;
cout << "Unoccupied Rooms on Floor 4: " << roomList.countUnoccupiedRooms(4) << endl;
return 0;
}
```
阅读全文