-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainCode.cpp
More file actions
455 lines (427 loc) · 18.7 KB
/
Copy pathMainCode.cpp
File metadata and controls
455 lines (427 loc) · 18.7 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
#include <iostream>
#include <cstring>
#include <fstream>
#include <windows.h>
#define infinity 999999999
using namespace std;
struct store {
long long int cost[20];
int array[20];
} travel[15];
struct initialdata {
long long int cost[20];
} ini[15];
class datamodule {
public:
string city[15];
datamodule() : city{"Mehrouli", "Noida Electronic City", "Sector 18", "Hauz Khaz", "CP", "Okla", "shaheen Bagh", "Chirag Delhi", "INA", "Sector 52", "Indirapuram", "Botanical Garden", "Sector 59", "Sikandarpur", "Preet Vihar"} {}
void costdeclaration() {
int N, i, j;
N = 15;
long long int arr[15][15] = {
{0, 35, 20, infinity, 10, infinity, infinity, infinity, infinity, 70, 40, 15, infinity, 65, infinity},
{35, 0, infinity, 15, infinity, infinity, infinity, 25, infinity, infinity, infinity, infinity, infinity, infinity, 50},
{20, infinity, 0, 15, infinity, 30, infinity, infinity, infinity, infinity, 20, 10, infinity, infinity, 15},
{infinity, 15, 15, 0, infinity, 12, 45, infinity, 60, infinity, infinity, infinity, infinity, infinity, 10},
{10, infinity, infinity, infinity, 0, 15, infinity, infinity, infinity, infinity, infinity, infinity, infinity, infinity, infinity},
{infinity, infinity, 30, 12, 15, 0, 19, infinity, infinity, infinity, infinity, infinity, infinity, infinity, infinity},
{infinity, infinity, infinity, 45, infinity, 19, 0, infinity, infinity, 20, infinity, infinity, infinity, infinity, infinity},
{infinity, 25, infinity, infinity, infinity, infinity, infinity, 0, 50, infinity, infinity, infinity, infinity, infinity, infinity},
{infinity, infinity, infinity, 60, infinity, infinity, infinity, 50, 0, 70, infinity, infinity, infinity, infinity, infinity},
{70, infinity, infinity, infinity, infinity, infinity, 20, infinity, 70, 0, infinity, infinity, infinity, infinity, infinity},
{40, infinity, 20, infinity, infinity, infinity, infinity, infinity, infinity, infinity, 0, infinity, infinity, infinity, infinity},
{15, infinity, 10, infinity, infinity, infinity, infinity, infinity, infinity, infinity, infinity, 0, infinity, infinity, infinity},
{infinity, infinity, infinity, infinity, infinity, infinity, infinity, infinity, infinity, infinity, infinity, infinity, 0, infinity, infinity},
{65, infinity, infinity, infinity, infinity, infinity, infinity, infinity, infinity, infinity, infinity, infinity, infinity, 0, infinity},
{infinity, 50, 150, 10, infinity, infinity, infinity, infinity, infinity, infinity, infinity, infinity, infinity, infinity, 0}
};
for (i = 0; i < N; i++) {
for (j = 0; j < N; j++) {
travel[i].cost[j] = arr[i][j];
travel[i].array[j] = j;
ini[i].cost[j] = arr[i][j];
}
}
}
};
class bellmanfordalgorithm : public datamodule {
public:
int N, i, j, k;
bellmanfordalgorithm() {
N = 15;
}
void algorithmic_implementation() {
for (i = 0; i < N; i++) {
for (j = 0; j < N; j++) {
for (k = 0; k < N; k++) {
if (travel[i].cost[j] > travel[i].cost[k] + travel[k].cost[j]) {
travel[i].cost[j] = travel[i].cost[k] + travel[k].cost[j];
travel[i].array[j] = k;
}
}
}
}
}
};
class filehandlingmodule {
public:
string username1, password1;
bool duplicatecheck(string username) {
ifstream fileread("login.txt");
while (fileread >> username1) {
if (username1 == username) {
fileread.close();
return false;
}
}
fileread.close();
return true;
}
void forgot(string username) {
system("cls");
int flag1 = 0;
string su, sp;
ifstream searchu("login.txt");
while (searchu >> su >> sp) {
if (su == username) {
flag1 = 1;
break;
}
}
searchu.close();
if (flag1 == 1) {
cout << "Congratulations " << su << " ! account found !" << endl;
cout << "Your password is: " << sp;
cin.get();
cin.get();
} else {
cout << "Sorry, your account is not found." << endl;
cin.get();
cin.get();
}
}
bool log_in(string username, string password) {
ifstream fileread("login.txt");
while (fileread >> username1 >> password1) {
if ((username == username1) && (password == password1)) {
cout << endl << " Account Login Successful..." << endl;
fileread.close();
return true;
}
}
fileread.close();
cout << "\n\n\t\tSorry, Login Error." << endl;
char f1;
cout << "\n\n\t\tRetrieve password by Username (Y/N): " << endl;
cin >> f1;
switch (f1) {
case 'Y':
case 'y':
forgot(username);
break;
case 'N':
case 'n':
return false;
}
return false;
}
void createaccount(string username, string password) {
ofstream filewrite("login.txt", ios::app);
filewrite << username << " " << password << "\n";
filewrite.close();
cout << endl << " Account is successfully Created ..." << endl;
}
void ticket(string username, string firstname[], string lastname[], string sex[], int age[], int no) {
ofstream filewrite("ticket.txt", ios::app);
for (int i = 0; i < no; i++) {
filewrite << username << " " << firstname[i] << " " << lastname[i] << " " << sex[i] << " " << age[i] << "\n";
}
filewrite.close();
}
};
class inputmodule {
public:
string source, destination;
string username, password;
void user_input(string userchoice[]) {
system("CLS");
cout << "\n\n *************************************************" << endl;
cout << endl;
cout << " *****************************************" << endl;
cout << " Enter Your City:";
cin >> source;
cout << " *****************************************" << endl;
cout << " Enter Your Destination:";
cin >> destination;
cout << " *****************************************" << endl;
userchoice[0] = source;
userchoice[1] = destination;
}
string login() {
while (true) {
cout << "\n\n ****************************WELCOME TO METRO PATH GENERATOR**************************" << endl;
cout << "\n\n\n\n";
cout << " ENTER " << endl;
cout << " *****************************************" << endl;
cout << " **** 1. To Login *****" << endl;
cout << " *****************************************" << endl;
cout << " **** 2. To Create New Account ****" << endl;
cout << " *****************************************" << endl;
cout << "\n Enter Your Choice:";
int ch;
bool res;
filehandlingmodule fobj;
cin >> ch;
switch (ch) {
case 1:
system("CLS");
cout << "\n\n**************************** WELCOME TO METRO PATH GENERATOR**************************" << endl;
cout << endl;
cout << "*****************************************" << endl;
cout << " Enter Username:";
cin >> username;
cout << "*****************************************" << endl;
cout << " Enter Your Password:";
cin >> password;
cout << "*****************************************" << endl;
res = fobj.log_in(username, password);
break;
case 2: {
int res2 = 0;
system("CLS");
cout << "\n\n**************************** WELCOME TO METRO PATH GENERATOR**************************" << endl;
cout << endl;
cout << "*****************************************" << endl;
cout << " Enter Username:";
cin >> username;
cout << "*****************************************" << endl;
cout << " Enter Your Password:";
cin >> password;
cout << "*****************************************" << endl;
res2 = fobj.duplicatecheck(username);
if (res2 == 1)
fobj.createaccount(username, password);
else
cout << "Duplicate account found, Try again" << endl;
break;
}
}
if (res == true)
return username;
}
}
int noofpassenger() {
int no;
cout << endl << " Enter the no of passengers:";
cin >> no;
return no;
}
};
class outputmodule {
public:
string source, destination;
void initial() {
system("CLS");
cout << "\n\n ****************************WELCOME TO METRO PATH GENERATOR**************************" << endl;
cout << "\n\n";
cout << " ***************************" << endl;
cout << " * Facilities Available: *" << endl;
cout << " ***************************" << endl;
cout << "\n\n";
cout << " ENTER " << endl;
cout << " **** 1. To Display List of Metros ****" << endl;
cout << " *****************************************" << endl;
cout << " **** 2. To Book Ticket ****" << endl;
cout << " *****************************************" << endl;
cout << " **** 3. Exit ****" << endl;
cout << " *****************************************" << endl;
}
void list_cities(int N) {
datamodule o;
cout << endl;
system("CLS");
cout << "\n\n ****************************WELCOME TO METRO PATH GENERATOR**************************" << endl;
cout << "\n\n";
cout << " The listed cities are:" << endl;
cout << " *****************************************" << endl;
for (int i = 0; i < N; i++) {
cout << " * " << o.city[i] << " " << endl;
cout << " *" << endl;
}
cout << " *****************************************" << endl;
}
void ticket(int total_price, int no, string source, string destination, string username) {
system("CLS");
cout << "\n\n **************************** E-TICKET**************************" << endl;
cout << endl << " This Ticket is issued for :" << username << endl;
cout << endl << " Source:" << source << endl;
cout << endl << " Destination:" << destination << endl;
cout << endl << " Total No of Passengers:" << no << endl;
cout << endl << " Total Cost:" << total_price << endl;
cout << "\n\n****************************************************************************" << endl;
}
void passengerdetailedticket(int no, string firstname[], string lastname[], string sex[], int age[]) {
for (int i = 0; i < no; i++) {
cout << " Passenger " << (i + 1) << " Details:" << endl << endl;
cout << " First Name: " << firstname[i] << endl;
cout << " Last Name: " << lastname[i] << endl;
cout << " Sex: " << sex[i] << endl;
cout << " Age: " << age[i] << endl;
cout << "\n\n****************************************************************************" << endl;
}
int ch;
cout << endl << " Enter 1 to continue:";
cin >> ch;
if (ch == 1) {
initial();
}
}
int display_price(string source, string destination, int N, string username) {
datamodule o;
inputmodule in;
int choiceofpassenger;
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
if (source == o.city[i] && destination == o.city[j]) {
cout << endl;
if (ini[i].cost[j] == infinity && travel[i].cost[j] == infinity) {
cout << " Sorry, There are no METRO available connecting the destination" << endl;
return 0;
} else if (ini[i].cost[j] == infinity) {
cout << " There is no direct metro from" << source << " to " << destination << ". So, Travel via other metro is only possible." << endl;
cout << " The Price is:" << travel[i].cost[j] << endl << endl;
cout << " The Route is:" << source;
int c1 = i, c2 = j;
while (c1 != c2) {
cout << "-->" << o.city[travel[c1].array[j]];
c1 = travel[c1].array[j];
}
cout << endl << endl;
} else if ((ini[i].cost[j] == 0) || (travel[i].cost[j] == 0)) {
cout << " You are here only xD " << endl;
return 0;
} else if ((ini[i].cost[j] != infinity) && (ini[i].cost[j] == travel[i].cost[j])) {
cout << " There is direct metro available from" << source << " to " << destination << " . And, it is cheapest among all other paths..." << endl;
cout << " The Price is:" << travel[i].cost[j] << endl;
} else if ((ini[i].cost[j] != infinity) && (ini[i].cost[j] > travel[i].cost[j])) {
cout << " There is direct metro available from" << source << " to " << destination << " ." << endl;
cout << " The Price is:" << ini[i].cost[j] << endl << endl;
cout << " *****************************************" << endl << endl;
cout << " You can go via other metro that will cost you less than direct flight." << endl;
cout << " The Price is:" << travel[i].cost[j] << endl << endl;
cout << " The Route is:" << source;
int c1 = i, c2 = j;
while (c1 != c2) {
cout << "-->" << o.city[travel[c1].array[j]];
c1 = travel[c1].array[j];
}
cout << endl << endl;
cout << " Press 1 to go by direct metro and Press 2 to go via other metro: ";
cin >> choiceofpassenger;
}
char c;
cout << endl;
cout << " Do You want to Continue(Y/N)?";
cin >> c;
if (c == 'Y' || c == 'y') {
int no = in.noofpassenger();
string firstname[no], lastname[no], sex[no];
int age[no];
for (int i = 0; i < no; i++) {
cout << endl;
cout << "*****************************************" << endl;
cout << " Passenger" << (i + 1) << ":" << endl << endl;
cout << " First Name:";
cin >> firstname[i];
cout << endl << " Last Name:";
cin >> lastname[i];
cout << endl << "Sex(Male/Female/Other):";
cin >> sex[i];
cout << endl << " Age:";
cin >> age[i];
}
int total_price;
if (choiceofpassenger == 1) {
total_price = no * ini[i].cost[j];
} else {
total_price = no * travel[i].cost[j];
}
cout << endl << " The total Price is:" << total_price << endl;
char y;
cout << " Do You want to confirm Your Ticket(Y/N)?";
cin >> y;
if (y == 'Y' || y == 'y') {
filehandlingmodule f;
f.ticket(username, firstname, lastname, sex, age, no);
ticket(total_price, no, source, destination, username);
passengerdetailedticket(no, firstname, lastname, sex, age);
} else {
cout << endl << " Thank You For choosing Us...";
cout << endl << " Do You Want to Continue(Y/N)?";
char ch;
cin >> ch;
if (ch == 'Y' || ch == 'y') {
initial();
}
return 0;
}
} else {
cout << endl << " Thank You For choosing Us...";
cout << endl << " Do You Want to Continue(Y/N)?";
char ch;
cin >> ch;
if (ch == 'N' || ch == 'n') {
initial();
}
return 0;
}
}
}
}
cout << " Sorry, There are no metros available connecting the destination!" << endl;
cout << endl << " Do You Want to Continue(Y/N)?";
char ch;
cin >> ch;
if (ch == 'Y' || ch == 'y') {
initial();
}
return 0;
}
};
int main() {
int N;
N = 15;
datamodule obj;
obj.costdeclaration();
bellmanfordalgorithm ob1;
ob1.algorithmic_implementation();
string userchoice[2];
inputmodule obj1;
string username;
username = obj1.login();
outputmodule object;
object.initial();
while (true) {
int choice;
cout << "\n Enter Your Choice:";
cin >> choice;
switch (choice) {
case 1:
object.list_cities(N);
cout << "\n\n Press 1 to Continue...";
int cont;
cin >> cont;
if (cont == 1) {
object.initial();
}
break;
case 2:
obj1.user_input(userchoice);
object.display_price(userchoice[0], userchoice[1], N, username);
break;
case 3:
return 0;
}
}
return 0;
}