-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHotelManagementSystem.cpp
100 lines (90 loc) · 2.97 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
//
// HotelManagementSystem.cpp
// projectfinal2
//
#include "HotelManagementSystem.h"
#include <fstream>
#include <iostream>
#include <sstream>
#include <iomanip>
using namespace std;
HotelManagementSystem::HotelManagementSystem(const string& filename) {
loadRoomsFromFile(filename);
}
void HotelManagementSystem::loadRoomsFromFile(const string& filename) {
ifstream file(filename);
if (file.is_open()) {
while (file.peek() != EOF) {
Room room;
room.loadFromFile(file);
rooms.push_back(room);
}
file.close();
} else {
cout << "Unable to open file" << endl;
}
}
void HotelManagementSystem::displayHotelDescription() const {
for (const auto& room : rooms) {
room.displayRoomInfo();
if (!room.getIsAvailable()) {
cout << "Total Bill: $" << fixed << setprecision(2) << room.calculateBill() << endl;
}
}
}
void HotelManagementSystem::checkInCustomer(int roomNumber, string customerName, string checkInDate, string checkOutDate) {
bool roomFound = false;
for (auto& room : rooms) {
if (room.getRoomNumber() == roomNumber && room.getIsAvailable()) {
room.bookRoom(customerName, checkInDate, checkOutDate);
roomFound = true;
cout << "Room Number " << roomNumber << " has been checked in to " << customerName
<< " from " << checkInDate << " to " << checkOutDate << "." << endl;
cout << "Total Bill: $" << fixed << setprecision(2) << room.calculateBill() << endl;
break;
}
}
if (!roomFound) {
cout << "Room Number " << roomNumber << " is either not available or does not exist." << endl;
}
}
void HotelManagementSystem::checkOutCustomer(int roomNumber) {
bool roomFound = false;
for (auto& room : rooms) {
if (room.getRoomNumber() == roomNumber && !room.getIsAvailable()) {
cout << "Room Number " << roomNumber << " has been checked out." << endl;
cout << "Total Bill: $" << fixed << setprecision(2) << room.calculateBill() << endl;
room.checkoutRoom();
roomFound = true;
break;
}
}
if (!roomFound) {
cout << "Room Number " << roomNumber << " is either not booked or does not exist." << endl;
}
}
void HotelManagementSystem::viewAvailableRooms() const {
for (const auto& room : rooms) {
if (room.getIsAvailable()) {
room.displayRoomInfo();
}
}
}
void HotelManagementSystem::viewBookedRooms() const {
for (const auto& room : rooms) {
if (!room.getIsAvailable()) {
room.displayRoomInfo();
}
}
}
void HotelManagementSystem::saveCurrentStateToFile(const string& filename) const {
ofstream file(filename);
if (file.is_open()) {
for (const auto& room : rooms) {
room.saveToFile(file);
}
file.close();
} else {
cout << "Unable to open file" << endl;
}
}