-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhotelmanagementsystem.cpp
105 lines (90 loc) · 3.17 KB
/
hotelmanagementsystem.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#include <iostream>
#include <vector>
#include <string>
#include <iomanip>
using namespace std;
// Structure to hold customer information
struct Customer {
string name;
string phone;
};
// Structure to hold room information
struct Room {
int roomNumber;
bool isOccupied;
Customer currentCustomer;
double ratePerNight;
};
// Class to handle the hotel management system
class HotelManagementSystem {
private:
vector<Room> rooms;
public:
HotelManagementSystem(int numRooms, double ratePerNight) {
for (int i = 0; i < numRooms; ++i) {
rooms.push_back({i + 1, false, {"", ""}, ratePerNight});
}
}
void showAvailableRooms() {
cout << "Available Rooms:\n";
for (const auto& room : rooms) {
if (!room.isOccupied) {
cout << "Room " << room.roomNumber << ", Rate: $" << room.ratePerNight << "\n";
}
}
}
void checkIn(const string& name, const string& phone, int roomNumber) {
for (auto& room : rooms) {
if (room.roomNumber == roomNumber) {
if (room.isOccupied) {
cout << "Room " << roomNumber << " is already occupied.\n";
} else {
room.isOccupied = true;
room.currentCustomer = {name, phone};
cout << "Customer " << name << " checked into room " << roomNumber << ".\n";
}
return;
}
}
cout << "Room " << roomNumber << " does not exist.\n";
}
void checkOut(int roomNumber) {
for (auto& room : rooms) {
if (room.roomNumber == roomNumber) {
if (room.isOccupied) {
cout << "Customer " << room.currentCustomer.name << " checked out from room " << roomNumber << ".\n";
room.isOccupied = false;
room.currentCustomer = {"", ""};
} else {
cout << "Room " << roomNumber << " is already empty.\n";
}
return;
}
}
cout << "Room " << roomNumber << " does not exist.\n";
}
void showBilling(int roomNumber, int nights) {
for (const auto& room : rooms) {
if (room.roomNumber == roomNumber) {
if (room.isOccupied) {
double totalBill = nights * room.ratePerNight;
cout << "Billing for room " << roomNumber << ": $" << fixed << setprecision(2) << totalBill << "\n";
} else {
cout << "Room " << roomNumber << " is not occupied.\n";
}
return;
}
}
cout << "Room " << roomNumber << " does not exist.\n";
}
};
int main() {
HotelManagementSystem hms(10, 100.0); // 10 rooms, $100 per night
hms.showAvailableRooms();
hms.checkIn("John Doe", "123-456-7890", 1);
hms.checkIn("Jane Smith", "987-654-3210", 2);
hms.showBilling(1, 3); // Billing for room 1 for 3 nights
hms.checkOut(1);
hms.showAvailableRooms();
return 0;
}