-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhostel booking system project .cpp
143 lines (122 loc) · 3.95 KB
/
hostel booking system project .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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#include <iostream>
#include <vector>
#include <string>
class Room {
public:
Room(int number, int capacity) : number(number), capacity(capacity), booked(false) {}
int getNumber() const {
return number;
}
int getCapacity() const {
return capacity;
}
bool isBooked() const {
return booked;
}
void book() {
booked = true;
}
void unbook() {
booked = false;
}
private:
int number;
int capacity;
bool booked;
};
class Reservation {
public:
Reservation(const std::string& guestName, const Room& room)
: guestName(guestName), room(room) {}
void display() const {
std::cout << "Reservation Details:" << std::endl;
std::cout << "Guest Name: " << guestName << std::endl;
std::cout << "Room Number: " << room.getNumber() << std::endl;
std::cout << "Room Capacity: " << room.getCapacity() << std::endl;
}
private:
std::string guestName;
const Room& room;
};
class HostelBookingSystem {
public:
void addRoom(const Room& room) {
rooms.push_back(room);
}
void displayAvailableRooms() const {
std::cout << "Available Rooms:" << std::endl;
for (const Room& room : rooms) {
if (!room.isBooked()) {
std::cout << "Room Number: " << room.getNumber() << " (Capacity: " << room.getCapacity() << ")" << std::endl;
}
}
}
bool bookRoom(int roomNumber, const std::string& guestName) {
for (Room& room : rooms) {
if (room.getNumber() == roomNumber && !room.isBooked()) {
room.book();
Reservation reservation(guestName, room);
reservations.push_back(reservation);
std::cout << "Room successfully booked." << std::endl;
return true;
}
}
std::cout << "Room not available for booking." << std::endl;
return false;
}
void displayReservations() const {
std::cout << "All Reservations:" << std::endl;
for (const Reservation& reservation : reservations) {
reservation.display();
std::cout << std::endl;
}
}
private:
std::vector<Room> rooms;
std::vector<Reservation> reservations;
};
int main() {
HostelBookingSystem system;
Room singleRoom1(101, 1);
Room singleRoom2(102, 1);
Room doubleRoom1(201, 2);
Room doubleRoom2(202, 2);
system.addRoom(singleRoom1);
system.addRoom(singleRoom2);
system.addRoom(doubleRoom1);
system.addRoom(doubleRoom2);
int choice;
do {
std::cout << "1. Display available rooms" << std::endl;
std::cout << "2. Book a room" << std::endl;
std::cout << "3. Display all reservations" << std::endl;
std::cout << "4. Exit" << std::endl;
std::cout << "Enter your choice: ";
std::cin >> choice;
switch (choice) {
case 1:
system.displayAvailableRooms();
break;
case 2: {
std::string guestName;
int roomNumber;
system.displayAvailableRooms();
std::cout << "Enter your name: ";
std::cin >> guestName;
std::cout << "Enter the room number: ";
std::cin >> roomNumber;
system.bookRoom(roomNumber, guestName);
break;
}
case 3:
system.displayReservations();
break;
case 4:
std::cout << "Exiting." << std::endl;
break;
default:
std::cout << "Invalid choice. Please enter a valid option." << std::endl;
}
} while (choice != 4);
return 0;
}