-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSource.cpp
More file actions
922 lines (777 loc) · 25.1 KB
/
Copy pathSource.cpp
File metadata and controls
922 lines (777 loc) · 25.1 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
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
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
#include <iostream>
#include <fstream>
#include <ctime>
#include<string>
#include<cstdlib>
//cls
#define maxStations 100
#define maxLines 3
using namespace std;
const int MaxUsers = 100;
const int MaxSub = 100;
int balance = 100;
//int firstLineStations, secondLineStations , thirdLineStations ;
int lineStations[3] = {35,20,29};
int numUsers = 2;
int numSub = 2;
struct Account {
string email;
string password;
};
// struct ride = date , destination departure , cost;
struct Subscription {
string subName;
int ValidityDays;
float SubPrice;
int index;
};
struct User {
int id;
Account UserAccount;
float Balance ;
Subscription Sub;
int rideCounter = 0;
string rideID[1000] ;
};
Subscription UsersSubscriptionTypes[MaxSub];
User users[MaxUsers];
struct MetroStations {
int id, line;
string name;
//arr [3] 4 = 1and2 5 = 2and3 6 =1and3
};
MetroStations stations[3][maxStations];
struct destination {
string station;
int id,line ;
};
struct departure {
string station;
int id, line;
};
struct ride {
string rideID[100000];
departure departure;
destination destination;
};
void StationsInitialization(MetroStations stations[3][maxStations]) {
// Initialize stations for Line 1
MetroStations line1Stations[] = {
{1, 1, "El Marg El Gedida"},
{2, 1, "El Marg"},
{3, 1, "Ezbet El Nakhl"},
{4, 1, "Ain Shams"},
{5, 1, "El-Matareyya"},
{6, 1, "Helmeyet El-Zaitoun"},
{7, 1, "Hadayek El-Zaitoun"},
{8, 1, "Saray El-Qobba"},
{9, 1, "Hammamat El-Qobba"},
{10, 1, "Kobri El-Qobba"},
{11, 1, "Manshiet El-Sadr"},
{12, 1, "El-Demerdash"},
{13, 1, "Ghamra"},
{14, 1, "Al Shohadaa"},
{15, 1, "Orabi"},
{16, 1, "Nasser"},
{17, 1, "Sadat"},
{18, 1, "Saad Zaghloul"},
{19, 1, "Al Sayeda Zeinab"},
{20, 1, "El-Malek El-Saleh"},
{21, 1, "Mar Girgis"},
{22, 1, "El-Zahraa"},
{23, 1, "Dar El-Salam"},
{24, 1, "Hadayek El-Maadi"},
{25, 1, "Maadi"},
{26, 1, "Sakanat El-Maadi"},
{27, 1, "Tora El-Balad"},
{28, 1, "Kozzika"},
{29, 1, "Tora El-Asmant"},
{30, 1, "El-Maasara"},
{31, 1, "Hadayek Helwan"},
{32, 1, "Wadi Hof"},
{33, 1, "Helwan University"},
{34, 1, "Ain Helwan"},
{35, 1, "Helwan"}
};
// Copy stations for Line 1 to the array of struct
for (int i = 0; i < lineStations[0]; ++i) {
stations[0][i] = line1Stations[i];
}
// Initialize stations for Line 2
MetroStations line2Stations[] = {
{1, 2, "Shubra El-Kheima"},
{2, 2, "Kolleyyet El-Zeraa"},
{3, 2, "Mezallat"},
{4, 2, "Khalafawy"},
{5, 2, "St. Teresa"},
{6, 2, "Rod El-Farag"},
{7, 2, "Masarra"},
{8, 2, "Al Shohadaa"},
{9, 2, "Ataba"},
{10, 2, "Mohamed Naguib"},
{11, 2, "Sadat"},
{12, 2, "Opera"},
{13, 2, "Dokki"},
{14, 2, "Bohooth"},
{15, 2, "Cairo University"},
{16, 2, "Faisal"},
{17, 2, "Giza"},
{18, 2, "Omm El-Misryeen"},
{19, 2, "Sakiat Mekki"},
{20, 2, "El-Monib"}
};
// Copy stations for Line 2 to the array of struct
for (int i = 0; i < lineStations[1]; ++i) {
stations[1][i] = line2Stations[i];
}
// Initialize stations for Line 3
MetroStations line3Stations[] = {
{1, 3, "Mohawar Rod El Farag"},
{2, 3, "Al Tareeq Al Daery"},
{3, 3, "Al Qawmeya Al Arabeya"},
{4, 3, "Al Bohy"},
{5, 3, "Imbaba"},
{6, 3, "Sudan"},
{7, 3, "El Kit Kat"},
{8, 3, "Safaa Hegazy"},
{9, 3, "Maspero"},
{10, 3, "Nasser"},
{11, 3, "Al Ataba"},
{12, 3, "Bab El Shaaria"},
{13, 3, "Al Gesh"},
{14, 3, "Abdu Basha"},
{15, 3, "Al Abbasiya"},
{16, 3, "Fair Zone"},
{17, 3, "Cairo Stadium"},
{18, 3, "Kolleyet El-Banat"},
{19, 3, "Al Ahram"},
{20, 3, "Haroun"},
{21, 3, "Heliopolis"},
{22, 3, "Alf Maskan"},
{23, 3, "Nady El Shams"},
{24, 3, "Al Nozha"},
{25, 3, "Hisham Barakat"},
{26, 3, "Qubba"},
{27, 3, "Omar Ibn El-Khattab"},
{28, 3, "Al Haykstep"},
{29, 3, "Adly Mansour"}
};
// Copy stations for Line 3 to the array of struct
for (int i = 0; i < lineStations[2]; ++i) {
stations[2][i] = line3Stations[i];
}
}
void inputDeparture(departure& userDeparture) {
cout << "Enter the metro line number you are going from: \n" << "Enter 1 or 2 or 3 \n";
cin >> userDeparture.line;
while (userDeparture.line != 1 && userDeparture.line != 2 && userDeparture.line != 3) {
cout << "you entered a wrong line number \n" << "Enter the metro line again: \n";
cout << "Enter 1 or 2 or 3" << endl;
cin >> userDeparture.line;
}
cout << "Enter your departure station " << endl;
cin.ignore();
getline(cin, userDeparture.station);
}
void inputDestination(destination& userDestination) {
cout << "Enter the metro line number you are heading: \n" << "Enter 1 or 2 or 3 \n";
cin >> userDestination.line;
while (userDestination.line != 1 && userDestination.line != 2 && userDestination.line != 3) {
cout << "you entered a wrong line number \n" << "Enter the metro line again: \n";
cout << "Enter 1 or 2 or 3"<<endl;
cin >> userDestination.line;
}
cout << "Enter your destination station " << endl;
cin.ignore();
getline(cin, userDestination.station);
}
/*void inputDepartureAndDestination(departure& userDeparture, destination& userDestination) {
cout << "Enter the metro line number you are going from: \n" << "Enter 1 or 2 or 3 \n";
cin >> userDeparture.line;
while (userDeparture.line != 1 && userDeparture.line != 2 && userDeparture.line != 3) {
cout << "you entered a wrong line number \n" << "Enter the metro line again: \n";
cout << "Enter 1 or 2 or 3\n";
cin >> userDeparture.line;
}
cout << "Enter your departure station \n";
cin.ignore();
getline(cin, userDeparture.station);
cout << "Enter the metro line number you are heading: \n" << "Enter 1 or 2 or 3 \n";
cin >> userDestination.line;
while (userDestination.line != 1 && userDestination.line != 2 && userDestination.line != 3) {
cout << "you entered a wrong line number \n" << "Enter the metro line again: \n";
cout << "Enter 1 or 2 or 3\n";
cin >> userDestination.line;
}
cout << "Enter your destination station \n";
cin.ignore();
getline(cin, userDestination.station);
}*/
int GetDepartureId(departure& userDeparture) {
int NumberOfStations;
bool stationFound = false; // to know if the station found or he entered a wrong name
do {
if (userDeparture.line == 1)
NumberOfStations = lineStations[0]; //35
else if (userDeparture.line == 2)
NumberOfStations = lineStations[1]; //20
else if (userDeparture.line == 3)
NumberOfStations = lineStations[2];//29
else return -1;
for (int i = 0; i < NumberOfStations; i++) {
if (userDeparture.station == stations[userDeparture.line - 1][i].name)
{
stationFound = true;
return stations[userDeparture.line - 1][i].id;
}
}
if (!stationFound) { // to handle wrong answers
cout << "Wrong station format try again:\n";
inputDeparture(userDeparture); // to input again
}
} while (stationFound == false);
}
int GetDestinationId(destination& userDestination) {
int NumberOfStations;
bool stationFound = 0; // to know if the station found or he entered a wrong name
do {
if (userDestination.line == 1)
NumberOfStations = 35;
else if (userDestination.line == 2)
NumberOfStations = 20;
else if (userDestination.line == 3)
NumberOfStations = 29;
else return -1;
for (int i = 0; i < NumberOfStations; i++) {
if (userDestination.station == stations[userDestination.line - 1][i].name) {
stationFound = true;
return stations[userDestination.line - 1][i].id;
break;
}
}
if (!stationFound)
cout << "Wrong station format try again:\n";
inputDestination(userDestination);
} while (true);
}
void purchaseMetroTicket(User user ,int subscriptionStage) {
if (subscriptionStage ==1)
{
user.Balance -= 8;
}
else if (subscriptionStage == 2)
{
user.Balance -= 12;
}
if (subscriptionStage == 3)
{
user.Balance -= 15;
}
}
int CalulateNumberOfStations(departure& userDeparture, destination& userDestination, int subscriptionStage, User user) {
int NumberOfStations;
if (userDeparture.line == userDestination.line)
NumberOfStations = abs(userDestination.id - userDeparture.id) + 1;
else if (userDeparture.line == 1 && userDestination.line == 2)
NumberOfStations = abs(userDeparture.id - 14) + abs(userDestination.id - 8) + 1;
else if (userDeparture.line == 1 && userDestination.line == 3) {
if (userDeparture.id <= 14 && userDestination.id >= 11)
NumberOfStations = abs(userDeparture.id - 16) + abs(userDestination.id - 10) - 1;
else
NumberOfStations = abs(userDeparture.id - 16) + abs(userDestination.id - 10) + 1;
}
else if (userDeparture.line == 2 && userDestination.line == 1)
NumberOfStations = abs(userDeparture.id - 8) + abs(userDestination.id - 14) + 1;
else if (userDeparture.line == 2 && userDestination.line == 3) {
if (userDeparture.id >= 11 && userDestination.id <= 10)
NumberOfStations = abs(userDeparture.id - 9) + abs(userDestination.id - 11) - 1;
else
NumberOfStations = abs(userDeparture.id - 9) + abs(userDestination.id - 11) + 1;
}
else if (userDeparture.line == 3 && userDestination.line == 1) {
if (userDeparture.id >= 11 && userDestination.id <= 14)
NumberOfStations = abs(userDeparture.id - 10) + abs(userDestination.id - 16) - 1;
else
NumberOfStations = abs(userDeparture.id - 10) + abs(userDestination.id - 16) + 1;
}
else if (userDeparture.line == 3 && userDestination.line == 2) {
if (userDeparture.id <= 10 && userDestination.id >= 11)
NumberOfStations = abs(userDeparture.id - 11) + abs(userDestination.id - 9) - 1;
else
NumberOfStations = abs(userDeparture.id - 10) + abs(userDestination.id - 16) + 1;
}
char option; // to choose either to choose again or to use balance
switch (subscriptionStage) // from the function of susbscription
{
case 1:
subscriptionStage = 1;
if (NumberOfStations > 9 && NumberOfStations <= 16) {
cout << "Numeber of stations is more than the stage you have chosen(stage 1)\n";
cout << "Do you want to purchase from your balance (y)? Or enter the destination again?(n)\n";
cin >> option;
if (option == 'Y' || option == 'y') {
purchaseMetroTicket(user, subscriptionStage); // to deduct from the balance
}
else if (option == 'n' || option == 'N') {
inputDeparture(userDeparture);
inputDestination( userDestination);
userDeparture.id = GetDepartureId(userDeparture);
userDestination.id = GetDestinationId(userDestination);
NumberOfStations = 0;
NumberOfStations = CalulateNumberOfStations(userDeparture, userDestination, subscriptionStage, user);
return NumberOfStations;
}
}
break;
case 2:
subscriptionStage = 2;
if (NumberOfStations > 16 && NumberOfStations<=23){
cout << "Numeber of stations is more than the stage you have chosen(stage 2)\n";
cout << "Do you want to purchase from your balance (y)? Or enter the destination again?(n)\n";
cin >> option;
if (option == 'Y' || option == 'y') {
purchaseMetroTicket(user, subscriptionStage); // to deduct from the balance
}
else if (option == 'n' || option == 'N') {
inputDeparture(userDeparture);
inputDestination(userDestination);
userDeparture.id = GetDepartureId(userDeparture);
userDestination.id = GetDestinationId(userDestination);
NumberOfStations = 0;
NumberOfStations = CalulateNumberOfStations(userDeparture, userDestination, subscriptionStage, user);
return NumberOfStations;
}
}
break;
case 3:
subscriptionStage = 3;
if (NumberOfStations > 23)
{
cout << "Numeber of stations is more than the stage you have chosen(stage 3)\n";
cout << "Do you want to purchase from your balance (y)? Or enter the destination again?(n)\n";
//stageValidation = false;
cin >> option;
if (option == 'Y' || option == 'y') {
purchaseMetroTicket(user, subscriptionStage);
}
else if (option == 'n' || option == 'N') {
inputDeparture(userDeparture);
inputDestination(userDestination);
userDeparture.id = GetDepartureId(userDeparture);
userDestination.id = GetDestinationId(userDestination);
NumberOfStations = 0;
NumberOfStations = CalulateNumberOfStations(userDeparture, userDestination, subscriptionStage, user);
return NumberOfStations;
}
}
break;
}
user.rideCounter++; // number of trips user has done
user.rideID[user.rideCounter -1] = to_string(user.id) + to_string(user.rideCounter); // id for each trip
return NumberOfStations;
}
void GetCurrentTime() {
cout << __TIME__;
}
/*void CurrentDateAndTime() {
// current date and time on the current system
time_t now = time(0);
string CurrentDateAndTime = ctime(&now);
cout << CurrentDateAndTime;
}*/
void GetCurrentDate() {
cout << __DATE__;
}
void ViewUsersAccounts(User users[MaxUsers]) {
cout << "Accounts:\n";
for (int i = 0; i < numUsers; i++) {
cout << "Email: " << users[i].UserAccount.email << "\n";
}
}
void EditUsersAccounts(User users[MaxUsers], int numUsers, int id) {
string NewEmail;
for (int i = 0; i < numUsers; i++) {
if (id == users[i].id) {
cout << "Enter the new email for the user:" << endl;
cin >> NewEmail;
users[i].UserAccount.email = NewEmail;
return;
}
}
cout << "User Not Found";
}
void DeleteUsersAccounts(User users[MaxUsers], int& numUsers, int id) {
for (int i = 0; i < numUsers; i++) {
if (id == users[i].id) {
users[i] = users[i + 1];
numUsers = numUsers - 1; // Decrement the count of users
cout << "User account deleted successfully!\n";
return;
cout << "User not found!\n";
}
}
}
void CreateNewPlan(Subscription UserSubscriptionTypes[], int& numSub) {
string newName;
int newValidityDays;
float newPrice;
int NewIndex;
bool IndexExists = false;
cin >> newName;
cin >> newValidityDays;
cin >> newPrice;
cin >> NewIndex;
if (numSub <= 100) {
UserSubscriptionTypes[numSub].subName = newName;
UserSubscriptionTypes[numSub].ValidityDays = newValidityDays;
UserSubscriptionTypes[numSub].SubPrice = newPrice;
// Check for existing index throughout all elements
for (int i = 0; i < numSub; i++) {
if (UserSubscriptionTypes[i].index == NewIndex) {
IndexExists = true;
break;
}
}
while (IndexExists) {
cout << "Subscription index already exists. Please enter a new index: ";
cin >> NewIndex;
IndexExists = false;
for (int i = 0; i < numSub; i++) {
if (UserSubscriptionTypes[i].index == NewIndex) {
IndexExists = true;
break;
}
}
}
UserSubscriptionTypes[numSub].index = NewIndex;
numSub++;
}
else {
cout << "Maximum number of subscription plans reached.\n";
}
}
void ModifySubscriptionAdmin(Subscription UsersSubscriptionTypes[], int index, int numSubscriptions) {
string newName;
int newValidityDays;
float newPrice;
int NewIndex;
bool IndexExists;
cin >> newName;
cin >> newValidityDays;
cin >> newPrice;
cin >> NewIndex;
for (int i = 0; i < numSub; i++) {
if (index == UsersSubscriptionTypes[i].index) {
UsersSubscriptionTypes[i].subName = newName;
UsersSubscriptionTypes[i].ValidityDays = newValidityDays;
UsersSubscriptionTypes[i].SubPrice = newPrice;
bool IndexExists = false;
for (int i = 0; i < numSub; i++) {
if (UsersSubscriptionTypes[i].index == NewIndex) {
IndexExists = true;
}
else {
UsersSubscriptionTypes[i].index = NewIndex;
}
}
while (IndexExists) {
cout << "Subscription index already exists. Please enter a new index: ";
cin >> NewIndex;
IndexExists = false;
for (int i = 0; i < numSub; i++) {
if (UsersSubscriptionTypes[i].index == NewIndex) {
IndexExists = true;
break;
}
}
}
}
}
}
void DeleteSubscriptions(Subscription UsersSubscriptionTypes[], int& numSub, int index) {
for (int i = 0; i < numSub; i++) {
if (index == users[i].id) {
UsersSubscriptionTypes[i] = UsersSubscriptionTypes[i + 1];
numSub = numSub - 1; // Decrement the count of users
cout << "User Subscription Plan deleted successfully!\n";
return;
cout << "Subscription Plan not found!\n";
}
}
}
void AddMetroStation(MetroStations stations[3][maxStations]) {
int lineNumber, NumberOfStations;
char option;
do {
bool stationAdded = false;
cout << "Enter the line you want to add a station to: ";
cin >> lineNumber;
if (lineNumber >= 1 && lineNumber <= 3) {
NumberOfStations = lineStations[lineNumber - 1];
if (NumberOfStations < maxStations) {
string NewStation;
cout << "Enter the name of the new station: ";
cin.ignore();
getline(cin, NewStation);
stations[lineNumber - 1][NumberOfStations].name = NewStation;
stations[lineNumber - 1][NumberOfStations].id = NumberOfStations + 1;
stations[lineNumber - 1][NumberOfStations].line = lineNumber;
NumberOfStations++;
lineStations[lineNumber - 1] = NumberOfStations; // Update the global variable
stationAdded = true;
}
else {
cout << "Cannot add more stations to this line. Maximum capacity reached.\n";
}
}
else {
cout << "Invalid line number!\n";
}
if (stationAdded) {
cout << "Station added successfully!\n";
}
else {
cout << "Error adding station!\n";
}
cout << "Do you want to add another station? (y/n): ";
cin >> option;
} while (option == 'y' || option == 'Y');
}
void ViewMetroStations(MetroStations stations[3][maxStations]) {
int lineNumber, NumberOfStations;
char option;
do {
cout << "Enter the line you want to view \n";
cin >> lineNumber;
if (lineNumber >= 1 && lineNumber <= 3) {
NumberOfStations = lineStations[lineNumber - 1];
cout << "Stations:\n";
for (int i = 0; i < NumberOfStations; i++) {
cout << i + 1 << "->" << stations[lineNumber - 1][i].name << "\n";
}
}
cout << "Do you want to view another line ? (y/n) \n";
cin >> option;
} while (option == 'y' || option == 'Y');
}
void EditMetroStation(MetroStations stations[3][maxStations]) {
int lineNumber, NumberOfStations, id;
string NewStation;
cout << "Enter the line you want to edit from: \n";
cin >> lineNumber;
cout << "Enter the number of the station you want to edit: ";
cin >> id;
if (lineNumber >= 1 && lineNumber <= 3) {
NumberOfStations = lineStations[lineNumber - 1];
bool stationFound = false;
for (int i = 0; i < NumberOfStations; i++) {
if (id == stations[lineNumber-1][i].id) {
cout << "Enter the new station for the metro:" << endl;
cin.ignore();
getline(cin, NewStation);
stations[lineNumber-1][i].name = NewStation;
return;
}
}
if (!stationFound)
cout << "Station not found!\n";
}
else {
cout << "Invalid line number!\n";
}
}
void DeleteMetroStation(MetroStations stations[3][maxStations]) {
int lineNumber, NumberOfStations, id;
cout << "Enter the line you want to delete from: \n";
cin >> lineNumber;
cout << "Enter the number of the station you want to delete: ";
cin >> id;
if (lineNumber >= 1 && lineNumber <= 3) {
NumberOfStations = lineStations[lineNumber - 1];
bool stationFound = false;
for (int i = 0; i < NumberOfStations; i++) {
if (id == stations[lineNumber - 1][i].id) {
// Shift stations after the deleted station one index to the left
for (int j = i; j < NumberOfStations - 1; j++) {
stations[lineNumber - 1][j] = stations[lineNumber - 1][j + 1];
}
NumberOfStations--; // Decrement the count of stations
cout << "Metro station deleted successfully!\n";
lineStations[lineNumber - 1] = NumberOfStations; // Update the global variable
stationFound = true;
break;
}
}
if (stationFound) {
// Update the global variable for the number of stations
if (lineNumber == 1)
lineStations[0] = NumberOfStations;
else if (lineNumber == 2)
lineStations[1] = NumberOfStations;
else if (lineNumber == 3)
lineStations[2] = NumberOfStations;
}
else {
cout << "Station not found!\n";
}
}
else {
cout << "Invalid line number!\n";
}
}
/*
void StoreTheDataOfStations(MetroStations stations[maxLines][maxStations]) {
ofstream outfile("stations.txt");
if (outfile.is_open()) {
for (int line = 0; line < maxLines; line++) {
for (int i = 0; i < lineStations[line]; i++) {
outfile << stations[line][i].line << " " << stations[line][i].id << " "
<< stations[line][i].name << endl;
}
}
outfile.close();
}
else {
cerr << "Error: Could not open stations file for writing." << endl;
}
}
void ReadFromFileTheDataOfStations(MetroStations stations[maxLines][maxStations]) {
ifstream infile("stations.txt");
if (infile.is_open()) {
for (int line = 0; line < maxLines; line++) {
for (int i = 0; i < maxStations; i++) {
infile >> stations[line][i].line >> stations[line][i].id
>> ws; // Consume whitespace
getline(infile, stations[line][i].name);
}
}
infile.close();
}
else {
cerr << "Error: Could not open stations file for reading." << endl;
}
}
*/
void StoreTheDataOfStations(MetroStations stations [3][maxStations]) {
ofstream outfile("stations.txt");
if (outfile.is_open()) {
for (int i = 0; i < lineStations[0]; i++) {
outfile << stations[0][i].line << "," << stations[0][i].id << ","
<< stations[0][i].name << endl;
}
for (int i = 0; i < lineStations[1]; i++) {
outfile << stations[1][i].line << "," << stations[1][i].id << ","
<< stations[1][i].name << endl;
}
for (int i = 0; i < lineStations[2]; i++) {
outfile << stations[2][i].line << "," << stations[2][i].id << ","
<< stations[2][i].name << endl;
}
outfile.close();
}
else {
cerr << "Error: Could not open stations file." << endl;
}
}
void ReadFromFileTheDataOfStations(MetroStations stations[3][maxStations]) {
std::ifstream infile("stations.txt");
if (infile.is_open()) {
for (int i = 0; i < lineStations[0]; i++) {
infile >> stations[0][i].line;
infile.ignore(); // Ignore the comma
infile >> stations[0][i].id;
infile.ignore(); // Ignore the comma
getline(infile, stations[0][i].name);
}
for (int i = 0; i < lineStations[1]; i++) {
infile >> stations[1][i].line;
if (stations[1][i].line == 3)
{
break;
}
infile.ignore(); // Ignore the comma
infile >> stations[1][i].id;
infile.ignore(); // Ignore the comma
getline(infile, stations[1][i].name);
}
for (int i = 0; i < lineStations[2]; i++) {
infile >> stations[2][i].line;
infile.ignore(); // Ignore the comma
infile >> stations[2][i].id;
infile.ignore(); // Ignore the comma
getline(infile, stations[2][i].name);
}
infile.close();
}
else {
cerr << "Error: Could not open stations file." << endl;
}
}
/*
void ReadFromFileTheDataOfStations(MetroStations stations[3][maxStations]) {
ifstream infile("stations.txt");
if (infile.is_open()) {
for (int i = 0; i < lineStations[0]; i++) {
infile >> stations[0][i].line >> stations[0][i].id
>> stations[0][i].name;
}
for (int i = 0; i < lineStations[1]; i++) {
infile >> stations[1][i].line >> stations[1][i].id
>> stations[1][i].name;
}
for (int i = 0; i < lineStations[2]; i++) {
infile >> stations[2][i].line >> stations[2][i].id
>> stations[2][i].name ;
}
infile.close();
}
else {
cerr << "Error: Could not open stations file." << endl;
}
}
*/
void WriteStationNumbersToFile() {
ofstream outfile("stationNumbers.txt");
if (outfile.is_open()) {
outfile << lineStations[0] <<" "<< lineStations [1]<<" "<< lineStations[2];
outfile.close();
}
else {
cerr << "Error: Could not open file for writing." << endl;
}
}
void ReadStationNumbersToFile() {
ifstream infile("stationNumbers.txt");
if (infile.is_open()) {
infile >> lineStations[0] >> lineStations[1] >> lineStations[2];
infile.close();
}
else {
cerr << "Error: Could not open file for reading." << endl;
}
}
int main() {
User user;
departure userDeparture;
destination userDestination;
//ReadStationNumbersToFile();
StationsInitialization(stations);
ReadFromFileTheDataOfStations(stations);
ViewMetroStations(stations);
DeleteMetroStation(stations);
EditMetroStation(stations);
AddMetroStation(stations);
ViewMetroStations(stations);
inputDeparture(userDeparture);
userDeparture.id = GetDepartureId(userDeparture);
inputDestination(userDestination);
userDestination.id = GetDestinationId(userDestination);
int subscriptionStage = 1;
int NumberOfStations = CalulateNumberOfStations(userDeparture, userDestination , subscriptionStage, user );
cout << NumberOfStations <<" Stations" << endl;
// alshohada 1st = [0][13] 2nd = [1][7]
// alattaba 2nd = [1][8] 3rd =[2][10]
// nasser 1st = [0][15] 3rd = [2][9]
StoreTheDataOfStations(stations);
WriteStationNumbersToFile();
}