-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.cpp
533 lines (508 loc) · 15.2 KB
/
main.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
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
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
#include <fstream>
#include <iostream>
#include <map>
#include <cstring>
#include "graphs.h"
#include "customers.h"
#include "admin.h"
#include <cstdlib>
#include <stdlib.h>
#include <ctime>
using namespace std;
//global variables
Admin Ad[3];
Agent Ag[15];
map <string, int> m;
Trie CT;
GraphInt cost_graph;
GraphFloat time_graph;
map<string, string> parent;
map<string, int> dist;
Plan P[10];
bool admin_logged_in = false;
void enter(); //forward declaration
void initLocations(){
string locations[50] = {
"Delhi", "Mumbai", "Hong Kong", "Tokyo", "Bangkok", "Singapore", "Sydney (Australia)", "Melbourne (Australia)",
"Dubai", "Cairo", "Moscow", "Stockholm", "Seoul", "Canada", "San Francisco (USA)",
"Washington DC (USA)", "LA (USA)", "Chicago (USA)", "New York (USA)", "Cape Town (South Africa)", "Rio (Brazil)", "Santiago", "Mexico City",
"Peru", "Miami (USA)", "London", "Berlin (Germany)", "Rome", "Paris", "Spain", "Havana"
};
for(int i=0; locations[i]!=""; i++){
m[locations[i]] = 1;
}
cout<<"Initiated locations map\n";
}
void print_path(string dest){
if(parent[dest]==dest){
cout<<dest<<" -->";
return;
}
print_path(parent[dest]);
cout<<dest<<" -->";
}
// -------------- Admin Portal -------------------
void visit_admin_portal(){
//create login fn
bool success = admin_logged_in || login_admin(Ad,2);
if(success){
admin_logged_in = true;
system("clear");
cout<<"*****---------- WELCOME TO ADMIN PORTAL ----------*****\n\n";
int x;
cout<<"1: Add a Location\n";
cout<<"2: View all Customers\n";
cout<<"3: View all Bookings\n";
cout<<"4: Navigate back\n";
cout<<"5: Exit\n";
cin>>x;
switch(x){
case 1: {
system("clear");
add_edge(cost_graph, time_graph);
cout<<"\nPress any key, followed by 'enter' key, to navigate back.\n";
char c;
cin>>c;
visit_admin_portal();
break;
}
case 2: {
system("clear");
view_all_customers();
cout<<"\nPress any key, followed by 'enter' key, to navigate back.\n";
char c;
cin>>c;
visit_admin_portal();
break;
}
case 3: {
view_all_bookings();
cout<<"\nPress any key, followed by 'enter' key, to navigate back.\n";
char c;
cin>>c;
visit_admin_portal();
break;
}
case 4: {
system("clear");
admin_logged_in = false;
enter();
break;
}
case 5: {
system("clear");
admin_logged_in = false;
cout<<"\nThank you for using the Travel Plan Management Software!\n";
cout<<"Built by ABHILASHA BANSAL & ABHAY GUPTA\n";
cout<<"Exitting now ...\n";
break;
}
default: {
cout<<"\nInvalid Input\n";
enter();
}
}
}
else{
cout<<"\nLogin failed, please go back & enter correct details again.\n";
cout<<"Press any key, followed by 'enter' key, to navigate back.\n";
char c;
cin>>c;
enter();
}
}
bool book_custom(Booking &B, string dest);
// -------FINDING A CUSTOM PLAN BASIS SINGLE LOCATION-----------
void find_a_plan(){
system("clear");
string dest;
cout<<"*****---------- CUSTOM PLAN ----------*****\n";
cout<<"Enter the name of a destination in correct format, to find a plan: ";
cin.ignore();
getline(cin, dest);
if(m.count(dest)==0){
cout<<"\nLocation not found!!\n";
cout<<"Redirecting you back, press any key followed by 'Enter' to proceed.\n";
char c;
cin>>c;
visit_customer_portal();
return;
}
else{
cout<<"Location found!\n";
cout<<"\nFlight cost: "<<dist[dest]<<endl;
cout<<"The minimum cost plan is for: "<<(2*dist[dest])+20000<<"INR.\n\n";
print_path(dest);
cout<<endl<<endl;
cout<<"Enter a choice to proceed further: \n";
cout<<"1: Book this plan\n";
cout<<"2: Enter another destination\n";
cout<<"3: Navigate back\n";
int choice;
cin>>choice;
if(choice==1){
//add booking code here
Booking B1;
bool done = book_custom(B1, dest);
if(done){
system("clear");
cout<<"\n*****---------- BOOKING CONFIRMED ----------*****\n";
cout<<"Your agent will get in touch with you soon!\n";
B1.printBooking();
cout<<"\nRedirecting you back, press any key followed by 'Enter' to proceed.\n";
char c;
cin>>c;
visit_customer_portal();
return;
}
else{
cout<<"\n\nSome error occured. Booking not done. Please try again.\n";
cout<<"Redirecting you back, press any key followed by 'Enter' to proceed.\n";
char c;
cin>>c;
visit_customer_portal();
return;
}
}
else if(choice==2){
find_a_plan();
return;
}
else {
visit_customer_portal();
return;
}
}
return;
}
// ------------- Booking Functionality -----------------
bool book_premade_package(Plan P, Booking &B){
system("clear");
cin.clear();
fflush(stdin);
string email;
cout<<"\nPS: You need to have a valid customer account to make a booking.\n";
cout<<"If you dont have an account press any key followed by 'enter', and you'd be redirected.\n";
cout<<"Enter your email: \n";
getline(cin, email);
bool exists = CT.search(email);
if(exists){
cout<<"\nEnter your name: ";
cin.getline(B.cust_name, 30, '\n');
strcpy(B.cust_email, email.c_str());
int i=0;
for(string s: P.l){
strcpy(B.places[i], s.c_str());
i++;
}
//B.places = P.l;
strcpy(B.agent_name, assign_Agent(Ag, 10).c_str());
cout<<"Enter preferred date of travel: ";
cin.getline(B.date, 20, '\n');
cout<<"Enter no of people: ";
cin>>B.no_of_people;
B.amount = (P.cost)*B.no_of_people;
fstream f1;
f1.open("bookings.txt", ios::app);
f1.write( (char*)&B, sizeof(B) );
f1.close();
}
else{
cout<<"\nCreate a valid account to make the booking.\n";
return false;
}
return true;
}
bool book_custom(Booking &B, string dest){
system("clear");
cin.clear();
fflush(stdin);
string email;
cout<<"\nPS: You need to have a valid customer account to make a booking.\n";
cout<<"If you dont have an account press any key followed by 'enter', and you'd be redirected.\n";
cout<<"Enter your email: \n";
getline(cin, email);
bool exists = CT.search(email);
if(exists){
cout<<"\nEnter your name: ";
cin.getline(B.cust_name, 30, '\n');
strcpy(B.cust_email, email.c_str());
strcpy(B.places[0], dest.c_str());
strcpy(B.agent_name, assign_Agent(Ag, 10).c_str());
cout<<"Enter preferred date of travel: ";
cin.getline(B.date, 20, '\n');
cout<<"Enter no of people: ";
cin>>B.no_of_people;
int cost = (dist[dest]*2) + 20000;
B.amount = (cost)*B.no_of_people;
fstream f1;
f1.open("bookings.txt", ios::app);
f1.write( (char*)&B, sizeof(B) );
f1.close();
}
else{
cout<<"\nCreate a valid account to make the booking.\n";
return false;
}
return true;
}
// --------Book one of those pre-existing packages-----------
void book_a_package(){
cout<<"................AVAILABLE PLANS.....................\n";
for(int i=0; i<10; i++){
//displaying available packages
cout<<i+1<<" "<<P[i].name_of_plan<<endl;
cout<<"Price per person: "<<P[i].cost<<endl;
cout<<"No of days: "<<P[i].no_of_days<<endl;
cout<<"Places: ";
for(string s: P[i].l){
cout<<s<<" ";
}
cout<<"\n\n";
}
cout<<"\nEnter a choice to proceed further: \n";
cout<<"1: Book one of these plans\n";
cout<<"2: Navigate back\n";
int c;
cin>>c;
if(c==1){
int choice;
cout<<"\nEnter the no of the plan you want to book: ";
cin>>choice;
Booking B1;
bool done = book_premade_package(P[choice-1], B1);
cout<<"Here\n";
if(done){
system("clear");
cout<<"\n*****---------- BOOKING CONFIRMED ----------*****\n";
cout<<"Your agent will get in touch with you soon!\n";
B1.printBooking();
cout<<"\nRedirecting you back, press any key followed by 'Enter' to proceed.\n";
char c;
cin>>c;
visit_customer_portal();
return;
}
else{
cout<<"\nSome error occured. Booking not done. Please try again.\n";
cout<<"Redirecting you back, press any key followed by 'Enter' to proceed.\n";
char c;
cin>>c;
visit_customer_portal();
return;
}
}
else{
visit_customer_portal();
return;
}
}
//Customer Login
bool customer_login(string &email){
string a, password;
cout<<"*****---------- CUSTOMER LOGIN ----------*****";
cout<<"\nEnter your email: ";
cin>>a;
email = a;
cout<<"Enter password: ";
cin>>password;
fstream f1;
f1.open("customers.txt", ios::in);
Customer C;
bool p=false;
while(!f1.eof()){
f1.read( (char*)&C, sizeof(Customer) );
if(C.email==email && C.password==password){
p = true;
break;
}
}
f1.close();
return p;
}
// -------------- Customer Portal -----------------
void visit_customer_portal(){
system("clear");
cout<<"\n*****---------- WELCOME TO THE CUSTOMER PORTAL ----------*****\n\n";
int x;
cout<<"1: Create an account\n";
cout<<"2: View all locations\n";
cout<<"3: Find a Plan\n";
cout<<"4: Book a Package\n";
cout<<"5: View your Bookings\n";
cout<<"6: Navigate back\n";
cout<<"7: Exit\n";
cin>>x;
switch(x){
case 1: {
bool p = createAccount(CT);
visit_customer_portal();
break;
}
case 2: {
system("clear");
cout<<"\n*****---------- AVAILABLE LOCATIONS ----------*****\n";
int i=0;
for(auto p: m){
i++;
if(i%5==1){
cout<<endl;
}
cout<<left;
cout<<setw(20)<<p.first<<" ";
}
char x;
cout<<"\n\nPress any key, followed by 'enter' key, to navigate back.\n";
cin>>x;
cin.clear();
fflush(stdin);
visit_customer_portal();
break;
}
case 3: {
find_a_plan();
break;
}
case 4: {
book_a_package();
break;
}
case 5: {
system("clear");
string email;
bool login_success = customer_login(email);
if(login_success){
int bookings;
cout<<"\n*****---------- YOUR BOOKINGS ----------*****\n";
fstream f1;
f1.open("bookings.txt", ios::in);
Booking B;
f1.read( (char*)&B, sizeof(Booking) );
while(!f1.eof()){
if(B.cust_email==email){
bookings++;
B.printBooking();
cout<<endl;
}
f1.read( (char*)&B, sizeof(Booking) );
}
if(bookings==0){
cout<<"\nNo bookings found for this account!\n";
}
f1.close();
cout<<"Press any key followed by 'enter' to navigate back.\n";
char c;
cin>>c;
visit_customer_portal();
}
else{
cout<<"\nLogin failed. Please try again.\n";
cout<<"Redirecting you. Press any key followed by 'enter' to continue.\n";
char c;
cin>>c;
visit_customer_portal();
}
break;
}
case 6: {
enter();
break;
}
case 7: {
system("clear");
cout<<"\nThank you for using the Travel Plan Management Software!\n";
cout<<"Built by ABHILASHA BANSAL & ABHAY GUPTA\n";
cout<<"Exitting now ...\n";
break;
}
default: {
cout<<"Invalid Input\n";
cout<<"Redirecting you back, press any key followed by 'Enter' to proceed.\n";
char c;
cin>>c;
visit_customer_portal();
}
}
}
//Entry Point
void enter(){
int a;
system("clear");
cout<<"\n*****---------- WELCOME ----------*****\n\n";
cout<<"1: Go to Admin Portal\n";
cout<<"2: Go to User Portal\n";
cout<<"3: Exit\n";
cin>>a;
switch(a){
case 1: {
visit_admin_portal();
break;
}
case 2: {
visit_customer_portal();
break;
}
case 3: {
system("clear");
cout<<"\nThank you for using the Travel Plan Management Software!\n";
cout<<"Built by ABHILASHA BANSAL & ABHAY GUPTA\n";
cout<<"Exitting now ...\n";
break;
}
default: {
cout<<"\nInvalid Input\n";
enter();
}
}
}
//Init cost and time graphs after reading places.txt
void initGraphs(){
//add code
int edges=0;
Edge E1;
fstream f1;
f1.open("places.txt", ios::in);
f1.read( (char*)&E1, sizeof(E1) );
cost_graph.addEdge(E1.dest_1, E1.dest_2, E1.cost);
while(!f1.eof()){
edges++;
f1.read( (char*)&E1, sizeof(E1) );
cost_graph.addEdge(E1.dest_1, E1.dest_2, E1.cost);
//cout<<"COOL ";
}
cout<<"Graphs initiated, "<<edges<<" edges created!\n";
f1.close();
}
int main(){
system("clear");
srand (time(NULL));
//initialising admins
initAdmins(Ad);
int agent_count;
//initialising travel agents
initAgents(Ag, agent_count);
cout<<agent_count<<" agents found!\n";
//cout<<Ag[0].name<<endl;
//initialising available travel locations
initLocations();
for(auto p: m){
cout<<p.first<<" ";
}
cout<<endl;
//cout<<&(CT)<<endl;
//initialisng customers
initCustomers(CT);
//Initialising cost & time graphs
initGraphs();
dijk_cost("Delhi", parent, dist, cost_graph.m);
cout<<endl;
initPlans(P, 10);
char x;
cout<<"Press any key, followed by 'enter' key, to start program.\n";
cin>>x;
cin.clear();
fflush(stdin);
enter();
//add more code
return 0;
}