-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathproject.cpp
More file actions
484 lines (431 loc) · 12.9 KB
/
project.cpp
File metadata and controls
484 lines (431 loc) · 12.9 KB
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
#include <bits/stdc++.h>
#include <conio.h>
#include <string>
using namespace std;
const int FirstRoom=81;
const int LastRoom = 581;
bool RoomOccupied[LastRoom];
int guestCount = 0;
char Continue;
struct Guest
{
string name;
int startDate;
int startMonth;
int endDate;
int endMonth;
string address;
int age;
int RoomNo;
};
queue<Guest> Guests;
void swap(Guest *a, Guest *b)
{
Guest t = *a;
*a = *b;
*b = t;
}
int partition(Guest arr[], int low, int high, int choice)
{
int pivotInt = arr[high].RoomNo;
string pivotStr = arr[high].name;
int i = (low - 1);
for (int j = low; j <= high - 1; j++)
{
if (choice == 1)
{
if (arr[j].RoomNo < pivotInt)
{
i++;
swap(&arr[i], &arr[j]);
}
}
else if (choice == 0)
{
if (arr[j].name.compare(pivotStr) < 0)
{
i++;
swap(&arr[i], &arr[j]);
}
}
}
swap(&arr[i + 1], &arr[high]);
return (i + 1);
}
void quickSort(Guest arr[], int low, int high, int choice)
{
if (low < high)
{
int pi = partition(arr, low, high, choice);
quickSort(arr, low, pi - 1, choice);
quickSort(arr, pi + 1, high, choice);
}
}
int binarySearch(Guest arr[], int n, int roomNo, string x, int choice)
{
int l = 0;
int r = n - 1;
while (l <= r)
{
int m = l + (r - l) / 2;
int res;
int compare = x.compare(arr[m].name);
if ((compare == 0 && choice == 0) || (roomNo == arr[m].RoomNo && choice == 1))
res = 0;
if (res == 0)
return m;
if ((compare > 0 && choice == 0) || (roomNo > arr[m].RoomNo && choice == 1))
l = m + 1;
else
r = m - 1;
}
return -1;
}
void InitializeRooms()
{
for (int i = FirstRoom; i < LastRoom; i++)
{
RoomOccupied[i] = false;
}
}
int calcDate(int day, int month)
{
return 100 * month + day;
}
void filter(int date, int month)
{
while (!Guests.empty())
{
if (calcDate(Guests.front().endDate, Guests.front().endMonth) < calcDate(date, month))
{
RoomOccupied[Guests.front().RoomNo] = false;
guestCount -= 1;
Guests.pop();
}
else
break;
}
}
void checkIn()
{
Guest newGuest;
string name;
int startDate;
int startMonth;
int endDate;
int endMonth;
string address;
int age;
int RoomNo;
cout << "Please enter the following data with regards to the guest details" << endl;
cout << endl;
cout << "Enter Guest Name -> ";
getline(cin >> ws, name);
cout << "Enter guest check in date (dd mm)-> ";
cin >> startDate >> startMonth;
if (startDate > 31 || startDate < 1 || startMonth > 12 || startMonth < 1)
{
do
{
cout << "Please enter a valid date" << endl;
cout << "Enter date again -> ";
cin >> startDate >> startMonth;
} while (startDate > 31 || startDate < 1 || startMonth > 12 || startMonth < 1);
}
cout << "Enter guest release date (dd mm) -> ";
cin >> endDate >> endMonth;
if (endDate > 31 || endDate < 1 || endMonth > 12 || endMonth < 1 || (endMonth < startMonth) || (endDate < startDate && endMonth <= startMonth))
{
do
{
cout << "Please enter a valid date" << endl;
cout << "Enter date again -> ";
cin >> endDate >> endMonth;
} while (endDate > 31 || endDate < 1 || endMonth > 12 || endMonth < 1 || (endMonth < startMonth) || (endDate < startDate && endMonth <= startMonth));
}
cout << "Enter Guest Address -> ";
getline(cin >> ws, address);
cout << "Enter guest age -> ";
cin >> age;
cout << "Please choose a room from the following list of unoccupied rooms -> ";
int count = 0;
for (int i = FirstRoom; i < LastRoom && count < 10; i++)
{
if (!RoomOccupied[i])
{
cout << i << " ";
count += 1;
}
}
cout << endl;
cout << "Enter the Room Number --> ";
cin >> RoomNo;
if (RoomOccupied[RoomNo] || RoomNo < 81 || RoomNo > 580)
{
do
{
cout << "This Room is not available. Please enter a Room Number again ->";
cin >> RoomNo;
} while (RoomOccupied[RoomNo]);
}
newGuest.name = name;
newGuest.startDate = startDate;
newGuest.startMonth = startMonth;
newGuest.endDate = endDate;
newGuest.endMonth = endMonth;
newGuest.address = address;
newGuest.age = age;
newGuest.RoomNo = RoomNo;
RoomOccupied[RoomNo] = true;
Guests.push(newGuest);
cout << endl;
cout << "The guest " << name << " was succesfully checked in" << endl;
cout << endl;
guestCount += 1;
cout << "##########################################################" << endl;
cout << endl;
}
void sortGuests()
{
int n = Guests.size();
Guest GuestsArray[n];
for (int i = 0; i < n; i++)
{
GuestsArray[i] = Guests.front();
Guests.pop();
}
int choice;
cout << "Enter 0 if you want to sort on the basis of name" << endl;
cout << "Enter 1 if you want to sort on the basis of Room No" << endl;
cout << endl;
cout << "Enter your choice here-> ";
cin >> choice;
quickSort(GuestsArray, 0, n - 1, choice);
cout << endl;
char info;
bool showname = true, showDates = true, showAddress = true, showRoomNo = true, showAge = true;
cout << "Would you like to see all information about the guests? (y/n) -> ";
cin >> info;
cout << endl;
if (info == 'n')
{
cout << "Enter the information youd like to display(y/n) " << endl;
cout << "name -> ";
cin >> info;
if (info == 'n')
showname = false;
cout << "Room No -> ";
cin >> info;
if (info == 'n')
showRoomNo = false;
cout << "Check in and Check out Dates ->";
cin >> info;
if (info == 'n')
showDates = false;
cout << "Address -> ";
cin >> info;
if (info == 'n')
showAddress = false;
cout << "Age -> ";
cin >> info;
if (info == 'n')
showAge = false;
}
cout << "The sorted list is " << endl;
cout << endl;
for (int i = 0; i < n; i++)
{
if (showname)
cout << "name: " << GuestsArray[i].name << endl;
if (showRoomNo)
cout << "Room No: " << GuestsArray[i].RoomNo << endl;
if (showDates)
{
cout << "Check in: " << GuestsArray[i].startDate << " / " << GuestsArray[i].startMonth << endl;
cout << "Check Out: " << GuestsArray[i].endDate << " / " << GuestsArray[i].endMonth << endl;
}
if (showAddress)
cout << "Address: " << GuestsArray[i].address << endl;
if (showAge)
cout << "Age: " << GuestsArray[i].age << endl;
cout << endl;
}
cout << "##########################################################" << endl;
cout << endl;
for (int i = 0; i < n; i++)
{
Guests.push(GuestsArray[i]);
}
}
void searchGuest()
{
int n = Guests.size();
Guest GuestsArray[n];
for (int i = 0; i < n; i++)
{
GuestsArray[i] = Guests.front();
Guests.pop();
}
int result;
cout << "Enter 0 if you want to search on the basis of name " << endl;
cout << "Enter 1 if you want to search on the basis of Room No " << endl;
int choice;
cout << "Enter your choice here -> ";
cin >> choice;
cout << endl;
quickSort(GuestsArray, 0, n - 1, choice);
if (choice == 0)
{
string name;
cout << "Enter the name you want to search-> ";
getline(cin >> ws, name);
cout << endl;
result = binarySearch(GuestsArray, n, 0, name, choice);
if (result == -1)
{
cout << "No such person exists in the system " << endl;
}
else
{
cout << "Your requested details are -> " << endl;
cout << endl;
cout << "Name : " << GuestsArray[result].name << endl;
cout << "Room no : " << GuestsArray[result].RoomNo << endl;
cout << "Check in date : " << GuestsArray[result].startDate << "/" << GuestsArray[result].startMonth << endl;
cout << "Release date : " << GuestsArray[result].endDate << "/" << GuestsArray[result].endMonth << endl;
cout << "Address : " << GuestsArray[result].address << endl;
cout << "Age : " << GuestsArray[result].age << endl;
}
}
else if (choice == 1)
{
int roomNo;
cout << "Enter the Room no you want to search -> ";
cin >> roomNo;
cout << endl;
result = binarySearch(GuestsArray, n, roomNo, "", choice);
if (result == -1)
{
cout << "This Room has not been alloted to anyone " << endl;
}
else
{
cout << "Your requested details are -> " << endl;
cout << endl;
cout << "Name : " << GuestsArray[result].name << endl;
cout << "Room no : " << GuestsArray[result].RoomNo << endl;
cout << "Check in date : " << GuestsArray[result].startDate << "/" << GuestsArray[result].startMonth << endl;
cout << "Release date : " << GuestsArray[result].endDate << "/" << GuestsArray[result].endMonth << endl;
cout << "Address : " << GuestsArray[result].address << endl;
cout << "Age : " << GuestsArray[result].age << endl;
}
}
cout << endl;
cout << "##########################################################" << endl;
cout << endl;
for (int i = 0; i < n; i++)
{
Guests.push(GuestsArray[i]);
}
}
void displayRooms()
{
cout << "Currently " << guestCount << " rooms are occupied and " << 500 - guestCount << " rooms are availabele " << endl;
cout << endl;
cout << "The occupied rooms are " << endl;
for (int i = FirstRoom; i < LastRoom; i++)
{
if (RoomOccupied[i])
cout << i << " ";
}
cout << endl;
cout << "The unoccupied rooms are " << endl;
for (int i = FirstRoom; i < LastRoom; i++)
{
if (!RoomOccupied[i])
cout << i << " ";
if (i % 20 == 0)
cout << endl;
}
cout << endl;
cout << "##########################################################" << endl;
cout << endl;
}
void Display()
{
bool end = false;
int day;
int month;
cout << "Enter today's date (dd mm) --> ";
cin >> day >> month;
if (day > 31 || day < 1 || month > 12 || month < 1)
{
do
{
cout << "Please enter a valid date" << endl;
cout << "Enter date again -> ";
cin >> day >> month;
} while (day > 31 || day < 1 || month > 12 || month < 1);
}
cout << endl;
filter(day, month);
cout << "Please choose among the following options" << endl;
cout << endl;
cout << "1. Check in a New Guest" << endl;
cout << "2. Sort The Guest List" << endl;
cout << "3. Search for a guest" << endl;
cout << "4. Display vacant and Occupied rooms" << endl;
cout << "5. Exit the portal" << endl;
cout << endl;
cout << "Enter your choice here --> ";
int choice;
cin >> choice;
cout << endl;
if (choice == 1)
{
if (guestCount < 500)
checkIn();
else
cout << "There are no more empty rooms" << endl;
}
else if (choice == 2)
{
sortGuests();
}
else if (choice == 3)
{
searchGuest();
}
else if (choice == 4)
{
displayRooms();
}
else if (choice == 5)
{
cout << "Are you sure you want to exit? (y/n)" << endl;
char confirmation;
cin >> confirmation;
if (confirmation == 'y')
{
cout << "Thank you for using the portal " << endl;
end = true;
}
}
else
{
cout << "INVALID INPUT" << endl;
}
if (!end)
Display();
}
int main()
{
cout << "###########################################################" << endl;
cout << endl;
cout << "WELCOME TO THE NIT SILCHAR QUARRENTINE FACILITY PORTAL" << endl;
cout << endl;
cout << "###########################################################" << endl;
cout << endl;
InitializeRooms();
Display();
}