-
Notifications
You must be signed in to change notification settings - Fork 0
/
CarxHotelReadClient.h
349 lines (242 loc) · 13.5 KB
/
CarxHotelReadClient.h
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
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
void select_car ( Car_Modal *car, char *car_company_name, char *car_type, const char *location ) {
clearScreen();
printf(GREEN"=> "RESET);
char user_location[30];
do {
puts ("Enter your locaiton...");
scanf ("%[^\n]", user_location);
while ( '\n' != getchar() );
if(check_name(user_location)) break;
else {
puts ("Sorry,\n We are not currently available here.");
puts ("Please, Re-Enter...");
continue;
}
}while (1);
unsigned int car_count = 0;
Car_Rental *cars = find_cars(user_location, &car_count);
// Handle the case where no cars are found
if (cars == NULL) {
return;
}
// Print header for the entire car_rental information
printf("\n\n");
// Loop through each car_rental
for (int i = 0; i < car_count; i++) {
// Check if the car_rental is valid (ID not equal to 0)
if (cars[i].id != 0) {
// Print header for each car_rental entry
printf(BLUE"------------------------------------------------------------------------\n");
printf(YELLOW"=> %d.\t"GREEN"car_rental_name: %s, location: %s, \n",
i + 1, cars[i].company_name, cars[i].city_name);
// Print SUVs information if available
if (0 != cars[i].n_suv) {
printf(BLUE"------------- SUVs -------------\n");
// Loop through each SUV
for (int j = 0; j < cars[i].n_suv; j++) {
// Print details of each SUV
printf(YELLOW"model: %5d| modal name: %10s| price: %6d\n"RESET,
cars[i].suv[j].modal, cars[i].suv[j].name, cars[i].suv[j].price);
}
}
// Print non-SUVs information if available
if (0 != cars[i].n_non_suv) {
printf(BLUE"---------- non-SUVs ----------\n");
// Loop through each non-SUV
for (int j = 0; j < cars[i].n_non_suv; j++) {
// Print details of each non-SUV
printf(YELLOW"model: %5d| modal name: %-10s| price: %6d\n"RESET,
cars[i].non_suv[j].modal, cars[i].non_suv[j].name, cars[i].non_suv[j].price);
}
}
// Print premium cars information if available
if (0 != cars[i].n_premium) {
printf(BLUE"---------- PREMIUMs ----------\n");
// Loop through each premium car
for (int j = 0; j < cars[i].n_premium; j++) {
// Print details of each premium car
printf(YELLOW"model: %5d| modal name: %-10s| price: %6d\n"RESET,
cars[i].premium[j].modal, cars[i].premium[j].name, cars[i].premium[j].price);
}
}
// Print footer for each car_rental entry
printf(BLUE"------------------------------------------------------------------------\n"RESET);
}
}
char choice = '1';
// checking the choice...
switch ( choice ) {
case '1': {
int select_car_index; // for getting the hotel user want
do {
printf ("Enter the serial number of the Car Rental: ");
scanf ("%d", &select_car_index); // reading the hotel user want
getchar(); // ! clearing the buffer
if (select_car_index < 0 || select_car_index > car_count) {
puts (RED"INVALID CAR-RENTAL-SERIAL-NUMBER."RESET);
continue;
}
display_selected_car_rental ( &cars[select_car_index - 1] );
// ! GETTING THE COMPANY NAME!!!
strcpy (car_company_name, cars[select_car_index - 1].company_name );
if (confirm_prompt()){
clearScreen();
char client_car_choice;
do {
printf (GREEN"%s",
"Select car type: \n"
"1.\tSUV\n"
"2\tnon-SUV\n"
"3.\tPremium\n=> "RESET);
client_car_choice = getchar();
getchar(); // clearing the buffer
switch (client_car_choice){
case '1':
strcpy (car_type, "SUV");
(*car) = display_cars( "SUV", cars[select_car_index - 1].company_name, cars[select_car_index - 1].suv, cars[select_car_index - 1].n_suv, location );
break;
case '2':
strcpy (car_type, "Sedan");
(*car) = display_cars( "Sedan", cars[select_car_index - 1].company_name, cars[select_car_index - 1].non_suv, cars[select_car_index - 1].n_non_suv, location );
break;
case '3':
strcpy (car_type, "Premium");
(*car) = display_cars( "Premium", cars[select_car_index - 1].company_name, cars[select_car_index - 1].premium, cars[select_car_index - 1].n_premium, location );
break;
default:
break;
}
}while (client_car_choice < '0' || client_car_choice > '3');
}
}while ( select_car_index < 0 || select_car_index > car_count );
break;
}
default :
puts ("INVALID!");
}
// Free the allocated memory for cars
free(cars);
}
// this function will read all the hotels and the car Rentals at the provided location and will give choice to user whether he can
// select among the given or need recommendations and then will generate ticket once the selection has done
void both_read_client ( const char *location ) {
int hotels_count = 0; // => for storing total car_rentals and hotels at the place
Hotel *hotels = find_hotels ( location, &hotels_count); // finding the totla hotels
// printf ("hotels_count: %d", hotels_count);
// CEHCKING FOR HOTELS AND DISIPLAYING THEM
if (hotels != NULL) {
// Process the retrieved hotels
for (int i = 0; i < hotels_count ; i++) {
// printf ("i = %d\n", i);
if (hotels[i].id != 0){ // just an extra check
// pringting the hotels
printf(BLUE"-------------------------------------------------------------------------------------------------------------------------------------\n");
// printing the hotels
printf(BLUE"-------------------------------------------------------------------------------------------------------------------------------------\n");
printf(YELLOW"=> %d.\t"BLUE"Hotel Name: %s, Location: %s\n", i + 1, hotels[i].hotel_name, hotels[i].city_name);
// Display cost for STANDARD room
printf(YELLOW" Standard Room: Rs. "RESET"%u per night\n", hotels[i].p_standard_room);
// Display cost for DELUXE room
printf(YELLOW" Deluxe Room: Rs. "RESET"%u per night\n", hotels[i].p_delux_room);
// Display cost for LUXURY room
printf(YELLOW" Luxury Room: Rs. "RESET"%u per night\n", hotels[i].p_luxury_room);
printf(BLUE"-------------------------------------------------------------------------------------------------------------------------------------\n"RESET);
}
}
// ! PROMPTING USER TO EITHER SELECT OR WANT RECOMENDATIONS
char choice;
puts ("\nCan you choose among these:\n");
do {
printf ("%s%s",
"1.\tSELECT.\n",
"2.\tWant Recommendations.\n"
"=> ");
scanf ("%c", &choice);
while ( '\n' != getchar()); // clearing buffer
if (choice < '0' || choice > '2') {
puts (RED"INVALID INPUT"RESET);
}
}while( choice < '0' || choice > '2');
switch ( choice ) {
case '1': { // CUSTOM PLAN
int select_hotel_index; // for getting the hotel user want
do {
printf ("Enter the serial number of the hotel: ");
scanf ("%d", &select_hotel_index); // reading the hotel user want
while('\n' != getchar()); // ! clearing the buffer
if (select_hotel_index < 0 || select_hotel_index > hotels_count) {
puts (RED"INVALID HOTEL SERIAL NUMBER."RESET);
continue;
}
clearScreen();
display_selected_hotel ( hotels[select_hotel_index - 1] );
if (confirm_prompt()){
char client_room_choice;
do { printf (GREEN"%s",
"Select room type: \n"
"1.\tstandard\n"
"2\tDelux\n"
"3.\tLuxury\n"RESET);
client_room_choice = getchar();
while ( '\n' != getchar()); // clearing the buffer
// declariing the variable to get the car credentails needed for generating the ticket
char car_company_name[30], car_type[8];
Car_Modal car;
// reading the nuumber of days
int days;
printf("%s"GREEN"=> "RESET,
"Enter number of days...");
scanf("%d", &days);
while ( '\n' != getchar() );
switch (client_room_choice){
case '1':
select_car ( &car, car_company_name, car_type, location);
generate_ticket (hotels[select_hotel_index-1].hotel_name, "Standard Room", hotels[select_hotel_index-1].n_standard_rooms, hotels[select_hotel_index-1].p_standard_room, &car, car_company_name, car_type, location, days);
puts ("Thanks for using this service.");
exit (EXIT_SUCCESS);
sleep(2);
break;
case '2':
select_car ( &car, car_company_name, car_type, location);
generate_ticket (hotels[select_hotel_index-1].hotel_name, "Deluxe Room", hotels[select_hotel_index-1].n_standard_rooms, hotels[select_hotel_index-1].p_standard_room, &car, car_company_name, car_type, location, days);
printf ("Generating ticket!\n");
puts ("Thanks for using this service.");
exit (EXIT_SUCCESS);
sleep(2);
break;
case '3':
select_car ( &car, car_company_name, car_type, location);
generate_ticket (hotels[select_hotel_index-1].hotel_name, "Luxury Room", hotels[select_hotel_index-1].n_standard_rooms, hotels[select_hotel_index-1].p_standard_room, &car, car_company_name, car_type, location, days);
printf ("Generating ticket!\n");
puts ("Thanks for using this service.");
exit (EXIT_SUCCESS);
sleep(2);
break;
default:
puts ("Wrong input.");
break;
}
}while (client_room_choice < '0' || client_room_choice > '3');
}
}while ( select_hotel_index < 0 || select_hotel_index > hotels_count );
break;
}
case '2':{
int days, budget, hotel_budget, car_budget = hotel_budget = budget = days = 0;
get_info(&days, &budget); // this function read days and budget
make_calculations(&days, &budget, &hotel_budget, &car_budget, (true) ); // this will update my budget
_get_hotels_under_budegt ( hotels, hotels_count, hotel_budget,car_budget, days, location);
exit (EXIT_SUCCESS);
break;
}
default :
puts ("INVALID!");
}
free(hotels); // freeing the allocaitng memory
}
return;
}