-
Notifications
You must be signed in to change notification settings - Fork 0
/
car_rental_system.cpp
998 lines (920 loc) · 32.8 KB
/
car_rental_system.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
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
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
#include <bits/stdc++.h>
#include<fstream>
using namespace std;
// Below we have implemented function to calculate number of days between two given dates.
const int monthDays[12] = { 31, 59, 90, 120, 151, 181, 212, 243,
273, 304, 334, 365 };
int countLeapYearDays(int d[]){
int years = d[2];
if (d[1] <= 2)
years--;
return ( (years / 4) - (years / 100) + (years / 400) );
}
int countNoOfDays(int date1[], int date2[]){
long int dayCount1 = (date1[2] * 365);
dayCount1 += monthDays[date1[1]];
dayCount1 += date1[0];
dayCount1 += countLeapYearDays(date1);
long int dayCount2 = (date2[2] * 365);
dayCount2 += monthDays[date2[1]];
dayCount2 += date2[0];
dayCount2 += countLeapYearDays(date2);
return ( abs(dayCount1 - dayCount2) );
}
class Car_db{
private:
int car_no;
int availaibility;
string Car_name;
int Car_rent_price;
string rented_from;
public :
Car_db(int car_number, int availability_status, const std::string& car_name, int rent_price, const std::string& rented_source)
{
car_no = car_number;
availaibility = availability_status;
Car_name = car_name;
Car_rent_price = rent_price;
rented_from = rented_source;
}
string c_name(){
return Car_name;
}
string r_from(){
return rented_from;
}
int rent(){
return Car_rent_price;
}
void update(int car_n, int new_rprice, string new_date){
car_no = car_n;
Car_rent_price = new_rprice;
rented_from = new_date;
}
void delet(){
availaibility = 0;
Car_name = "";
car_no = 0;
Car_rent_price = 0;
rented_from = "000000";
}
int av(){
return availaibility;
}
void setav(){
availaibility = !availaibility;
}
void ch_rfrom(string date){
rented_from = date;
}
};
vector<Car_db> CARS;
class Customer_db{
private:
int id;
string name;
int Fine_dues;
int Customer_Record;
public :
vector<pair<int,string>> Return_dates;
vector<int> cars_rented;
Customer_db(int customer_id, const std::string& customer_name, const std::vector<int>& rented_cars,
int fine_dues, int customer_record, const std::vector<std::pair<int, std::string>>& return_dates)
{
id = customer_id;
name = customer_name;
cars_rented = {};
Fine_dues = fine_dues;
Customer_Record = customer_record;
Return_dates = {};
}
int size_rcars(){
return cars_rented.size();
}
int c_record(){
return Customer_Record;
}
void ch_record(int val){
Customer_Record -=val;
}
int c_rented(int ind){
return cars_rented[ind];
}
void c_f_dues(int p){
Fine_dues+=p;
}
int f_dues(){
return Fine_dues;
}
int rd_size(){
return Return_dates.size();
}
int ID(){
return id;
}
void del(){
name = "";
Fine_dues = 0;
cars_rented = vector<int>();
Customer_Record = 0;
Return_dates = vector<pair<int,string>>();
}
string c_name(){
return name;
}
string r2(int ind){
return Return_dates[ind].second;
}
int r1(int ind){
return Return_dates[ind].first;
}
};
vector<Customer_db> CUSTOMER;
class Employee_db{
private:
int id;
string name;
float Fine_dues;
int Employee_Record;
public:
vector<int> cars_rented;
vector<pair<int,string>> Return_dates;
Employee_db(int e_id, const std::string& e_name, const std::vector<int>& rented_cars,
int fine_dues, int e_record, const std::vector<std::pair<int, std::string>>& return_dates){
id = e_id;
name = e_name;
cars_rented = {};
Fine_dues = fine_dues;
Employee_Record = e_record;
Return_dates = {}; }
int size_rcars(){
return cars_rented.size();
}
int e_record(){
return Employee_Record;
}
void eh_record(int val){
Employee_Record -=val;
}
int e_rented(int ind){
return cars_rented[ind];
}
void e_f_dues(float p){
Fine_dues+=p;
}
int e_dues(){
return Fine_dues;
}
int rd_size(){
return Return_dates.size();
}
int ID(){
return id;
}
void del(){
name = "";
Fine_dues = 0;
cars_rented = vector<int>();
Employee_Record = 0;
Return_dates = vector<pair<int,string>>();
}
string e_name(){
return name;
}
string r2(int ind){
return Return_dates[ind].second;
}
int r1(int ind){
return Return_dates[ind].first;
}
};
vector<Employee_db> EMPLOYEE;
class Customer{
public:
int id;
void Rented_Cars( int id){
std:: cout<<"You have rented "<<CUSTOMER[id].size_rcars()<<" cars\n";
if(CUSTOMER[id].size_rcars()>0){
std:: cout<<"The following are the names of the cars rented : \n";
for(int index=0;index<CUSTOMER[id].size_rcars();index++){
int car_id = CUSTOMER[id].c_rented(index);
std:: cout<<index+1<<")"<<" "<<CARS[car_id].c_name()<<endl;
}
}
}
public :
void Fine_dues( int id){
int total_dues = 0;
std:: cout<<"The following are your pending dues:\n";
if(CUSTOMER[id].rd_size()==0)std:: cout<<"Total pending dues to be paid: "<<CUSTOMER[id].f_dues()<<endl;
else{
total_dues = 0;
for(int ind = 0; ind < CUSTOMER[id].rd_size(); ind++){
int cr_id = CUSTOMER[id].r1(ind);
string r_dt = CUSTOMER[id].r2(ind);
string i_dt = CARS[cr_id].r_from();
int date1[3] = {(i_dt[0]-'0')*10+(i_dt[1]-'0'), (i_dt[2]-'0')*10+(i_dt[3]-'0') , (i_dt[4]-'0')*10+(i_dt[5]-'0') };
int date2[3] = {(r_dt[0]-'0')*10+(r_dt[1]-'0'), (r_dt[2]-'0')*10+(r_dt[3]-'0') , (r_dt[4]-'0')*10+(r_dt[5]-'0') };
int rented_days = countNoOfDays(date1, date2);
int this_price = CARS[cr_id].rent() * rented_days;
std:: cout<<"Car Name : "<<CARS[cr_id].c_name()<<" Rent to be paid : "<<this_price<<endl;
total_dues+=this_price;
}
std:: cout<<"Total dues to be paid: "<<total_dues + CUSTOMER[id].f_dues()<<endl;
}
CUSTOMER[id].c_f_dues(total_dues);
}
void see_cars(){
int flag = 0;
for(int car_num = 0; car_num < CARS.size(); car_num++){
if(CARS[car_num].av()== 1) {
std:: cout<<"CAR_NUMBER = "<<car_num<<" CAR_NAME = "<<CARS[car_num].c_name()<<" RENT_PRICE = "<<CARS[car_num].rent()<<endl;
flag++;
}
}
if(flag==0)std:: cout<<"Sorry, No cars are availaible for now.";
else std:: cout<<"These cars are availaible for renting.\n";
}
void rent_car(){
std:: cout<<"Provide the number of the car you want to rent.\n";
int car_no;
std::cin>>car_no;
std:: cout<<"This car has per day rental price "<<CARS[car_no].rent()<<endl;
cout<<"To confirm Press 1 otherwise select other car press other digit.\n";
int c;
cin>>c;
if (std::cin.fail()) {
std:: cout << "Failed reading number, Try again." << endl;
return ;
}
if(c==1){
CARS[car_no].setav();
CUSTOMER[id].cars_rented.push_back(car_no);
std:: cout<<"Enter today's date in ddmmyy format.\n";
string date;
std::cin>>date;
CARS[car_no].ch_rfrom(date);
std:: cout<<"Enter the date you will be returning this car in ddmmyy format.\n";
string re_date;
std::cin>>re_date;
CUSTOMER[id].Return_dates.push_back({car_no,re_date});
int date1[3] = {(date[0]-'0')*10+(date[1]-'0'), (date[2]-'0')*10+(date[3]-'0') , (date[4]-'0')*10+(date[5]-'0') };
int date2[3] = {(re_date[0]-'0')*10+(re_date[1]-'0'), (re_date[2]-'0')*10+(re_date[3]-'0') , (re_date[4]-'0')*10+(re_date[5]-'0') };
cout<< "You have to pay " <<CARS[car_no].rent()*countNoOfDays(date1,date2)<<endl;
}
else rent_car();
}
};
class Employee{
public:
int id;
void Rented_Cars( int id){
std:: cout<<"You have rented "<<EMPLOYEE[id].cars_rented.size()<<" cars\n";
if(EMPLOYEE[id].cars_rented.size()>0){
std:: cout<<"The following are the names of the cars rented : \n";
for(int index=0;index<EMPLOYEE[id].cars_rented.size();index++){
int car_id = EMPLOYEE[id].cars_rented[index];
std:: cout<<index+1<<")"<<" "<<CARS[car_id].c_name()<<endl;
}
}
}
public :
void Fine_dues( int id){
std:: cout<<"The following are your pending dues:\n";
if(EMPLOYEE[id].Return_dates.size()==0)std:: cout<<"There are NO pending dues.\n";
else{
float total_dues = 0;
for(int ind = 0; ind < EMPLOYEE[id].Return_dates.size(); ind++){
int cr_id = EMPLOYEE[id].Return_dates[ind].first;
string r_dt = EMPLOYEE[id].Return_dates[ind].second;
string i_dt = CARS[cr_id].r_from();
int date1[3] = {(i_dt[0]-'0')*10+(i_dt[1]-'0'), (i_dt[2]-'0')*10+(i_dt[3]-'0') , (i_dt[4]-'0')*10+(i_dt[5]-'0') };
int date2[3] = {(r_dt[0]-'0')*10+(r_dt[1]-'0'), (r_dt[2]-'0')*10+(r_dt[3]-'0') , (r_dt[4]-'0')*10+(r_dt[5]-'0') };
int rented_days = countNoOfDays(date1, date2);
float this_price = CARS[cr_id].rent() * rented_days;
std:: cout<<"Car Name : "<<CARS[cr_id].c_name()<<" Rent to be paid : "<<this_price<<endl;
total_dues+=this_price;
}
std:: cout<<"Total dues to be paid: "<<0.85*total_dues<<endl;
}
}
void see_cars(){
int flag = 0;
for(int car_num = 0; car_num < CARS.size(); car_num++){
if(CARS[car_num].av() == 1) {
std:: cout<<"CAR_NUMBER = "<<car_num<<" CAR_NAME = "<<CARS[car_num].c_name()<<" RENT_PRICE = "<<CARS[car_num].rent()<<endl;
flag++;
}
}
if(flag==0)std:: cout<<"Sorry, No cars are availaible for now.";
else std:: cout<<"These cars are availaible for renting.\n";
}
void rent_car(){
std:: cout<<"Provide the number of the car you want to rent.\n";
int car_no;
std::cin>>car_no;
std:: cout<<"This car has per day rental price "<<CARS[car_no].rent()<<endl;
cout<<"To confirm Press 1 otherwise select other car press other digit.\n";
int c;
cin>>c;
if (std::cin.fail()) {
std:: cout << "Failed reading number, Try again." << endl;
return ;
}
if(c==1){
CARS[car_no].setav();
CUSTOMER[id].cars_rented.push_back(car_no);
std:: cout<<"Enter today's date in ddmmyy format.\n";
string date;
std::cin>>date;
CARS[car_no].ch_rfrom(date);
std:: cout<<"Enter the date you will be returning this car in ddmmyy format.\n";
string re_date;
std::cin>>re_date;
EMPLOYEE[id].Return_dates.push_back({car_no,re_date});
int date1[3] = {(date[0]-'0')*10+(date[1]-'0'), (date[2]-'0')*10+(date[3]-'0') , (date[4]-'0')*10+(date[5]-'0') };
int date2[3] = {(re_date[0]-'0')*10+(re_date[1]-'0'), (re_date[2]-'0')*10+(re_date[3]-'0') , (re_date[4]-'0')*10+(re_date[5]-'0') };
cout<< "You have to pay " <<CARS[car_no].rent()*countNoOfDays(date1,date2)<<endl;
}
else rent_car();
}
};
class Manager : public Customer, public Employee{
public:
void add_customer(string name){
int id = CUSTOMER.size();
Customer_db tmp(id,name,{},0,100,{});
CUSTOMER.push_back(tmp);
std:: cout<<"Customer Added with Customer ID "<<id<<endl;
}
void delete_customer( int id){
CUSTOMER[id].del();
}
void update_customer( int id, int car_id, string late_date){
string i_dt = CARS[car_id].r_from();
int date1[3] = {(i_dt[0]-'0')*10+(i_dt[1]-'0'), (i_dt[2]-'0')*10+(i_dt[3]-'0') , (i_dt[4]-'0')*10+(i_dt[5]-'0') };
int date2[3] = {(late_date[0]-'0')*10+(late_date[1]-'0'), (late_date[2]-'0')*10+(late_date[3]-'0') , (late_date[4]-'0')*10+(late_date[5]-'0') };
int late_days = countNoOfDays(date1, date2);
int extra_fine = late_days*CARS[car_id].rent();
CUSTOMER[id].c_f_dues(extra_fine);
CUSTOMER[id].ch_record(late_days);
std:: cout<< extra_fine <<"extra fine has been imposed due to late return.";
}
void list_customers(){
for(int i=0;i<CUSTOMER.size();i++){
if(CUSTOMER[i].c_record() >= 20){
std:: cout<<"Customer Id "<<CUSTOMER[i].ID()<<" Customer Name "<<CUSTOMER[i].c_name()<<endl;
}
}
}
void add_employee(string name){
int id = EMPLOYEE.size();
Employee_db tmp(id,name,{},0,100,{});
EMPLOYEE.push_back(tmp);
std:: cout<<"Employee added with Employee ID "<<id<<endl;
}
void delete_employee( int id){
EMPLOYEE[id].del();
}
void update_employee( int id, int car_id, string late_date){
string i_dt = CARS[car_id].r_from();
int date1[3] = {(i_dt[0]-'0')*10+(i_dt[1]-'0'), (i_dt[2]-'0')*10+(i_dt[3]-'0') , (i_dt[4]-'0')*10+(i_dt[5]-'0') };
int date2[3] = {(late_date[0]-'0')*10+(late_date[1]-'0'), (late_date[2]-'0')*10+(late_date[3]-'0') , (late_date[4]-'0')*10+(late_date[5]-'0') };
int late_days = countNoOfDays(date1, date2);
float extra_fine = late_days*CARS[car_id].rent();
EMPLOYEE[id].e_f_dues(0.85*extra_fine);
EMPLOYEE[id].eh_record(late_days);
std:: cout<< extra_fine <<"extra fine has been imposed due to late return.";
}
void list_employees(){
for(int i=0;i<EMPLOYEE.size();i++){
if(EMPLOYEE[i].e_record() != 0){
std:: cout<<"Employee Id "<<EMPLOYEE[i].ID()<<" Employee Name "<<EMPLOYEE[i].e_name()<<endl;
}
}
}
void add_car(string car_name, int rent_price, string todays_date){
Car_db tmp_car(CARS.size(),1,car_name,rent_price,todays_date);
CARS.push_back(tmp_car);
std:: cout << car_name <<" has been added and assigned number is "<<CARS.size()-1<<endl;
}
void delete_car(int car_no){
if(CARS[car_no].av()==1){
CARS[car_no].delet();
std:: cout<<"This car has been deleted from the record.\n";}
else if(CARS[car_no].av() == 0){
cout<<"This car is not availaible for deletion.\n";
}
}
void update_car(int car_no, int new_rprice, string new_date){
CARS[car_no].update(car_no,new_rprice,new_date);
std:: cout<<"The details of this car have been updated.\n";
}
};
int main(){
// Declaring CARS DataBase.
vector<string> CarNames = {"Toyota Camry", "Honda Accord", "Ford Fusion", "Chevrolet Malibu",
"Nissan Altima", "Hyundai Sonata", "Kia Optima", "Mazda6",
"Volkswagen Passat", "Subaru Legacy"};
for (int i = 0; i < 10; ++i) {
Car_db car_entry(i,1,CarNames[i],100+10*i,"030324");
CARS.push_back(car_entry);
}
// Declaring CUSTOMER DataBase.
for (int i = 0; i <= 9; ++i) {
Customer_db customer_entry(i,"Customer"+to_string(i+1),{},0,100,{});
CUSTOMER.push_back(customer_entry);
}
// Declaring Employee DataBase.
for (int i = 0; i <= 9; ++i) {
Employee_db employee_entry(i,"Employee"+to_string(i+1),{},0,100,{});
EMPLOYEE.push_back(employee_entry);
}
// Starting the System.
std:: cout<<"WELCOME TO CAR RENTAL SYSTEM :)\n";
int stay = 1;
while(stay){
std:: cout<<"Specify your role.\n"<<"Press 1 if you are CUSTOMER.\n"<<"Press 2 if you are MANAGER\n"<<"Press 3 if you are EMPLOYEE.\n";
int role;
std::cin>>role;
if (std::cin.fail()) {
std:: cout << "Failed reading number, Try again." << endl;
return 1;
}
else if(role==1){
std:: cout<<"Please enter your Customer ID.\n";
int Customer_ID;
std::cin>>Customer_ID;
if (std::cin.fail()) {
std:: cout << "Failed reading number, Try again." << endl;
return 1;
}
if(Customer_ID>=CUSTOMER.size()){
"You are not a validated CUSTOMER.\n";
}
else{
std:: cout<<"How can we help you?\n";
std:: cout<<"Press 1 to see menu.\n";
int menu;
std::cin>>menu;
if (std::cin.fail()) {
std:: cout << "Failed reading number, Try again." << endl;
return 1;
}
while(menu){
std:: cout<<"Press 1 if you want to see the availaible cars.\n"<<"Press 2 if you want to see your fine dues.\n"<<"Press 3 if you want to see cars you have rented out.\n"<<"Press 4 if you want to rent a car.\n";
int enquiry;
std::cin>>enquiry;
if (std::cin.fail()) {
std:: cout << "Failed reading number, Try again." << endl;
return 1;
}
else if(enquiry == 1){
Customer c;
c.id = Customer_ID;
c.see_cars();
int forward;
std:: cout<<"Press 0 to exit, to continue enter any other digit \n";
std::cin>>forward;
if (std::cin.fail()) {
std:: cout << "Failed reading number, Try again." << endl;
return 1;
}
menu = forward;
}
else if(enquiry == 2){
Customer c;
c.id = Customer_ID;
c.Fine_dues(Customer_ID);
int forward;
std:: cout<<"Press 0 to exit, to continue enter any other digit \n";
std::cin>>forward;
if (std::cin.fail()) {
std:: cout << "Failed reading number, Try again." << endl;
return 1;
}
menu = forward;
}
else if(enquiry == 3){
Customer c;
c.id = Customer_ID;
c.Rented_Cars(Customer_ID);
int forward;
std:: cout<<"Press 0 to exit, to continue enter any other digit \n";
std::cin>>forward;
if (std::cin.fail()) {
std:: cout << "Failed reading number, Try again." << endl;
return 1;
}
menu = forward;
}
else if(enquiry == 4){
Customer c;
c.id = Customer_ID;
c.rent_car();
int forward;
std:: cout<<"Press 0 to exit, to continue enter any other digit \n";
std::cin>>forward;
if (std::cin.fail()) {
std:: cout << "Failed reading number, Try again." << endl;
return 1;
}
menu = forward;
}
else{
std:: cout<<"Enter a valid input\n";
int forward;
std:: cout<<"Press 0 to exit, to continue enter any other digit \n";
std::cin>>forward;
if (std::cin.fail()) {
std:: cout << "Failed reading number, Try again." << endl;
return 1;
}
menu = forward;
}
}
}
}
else if(role==2){
int t = 1;
while(t){
int to_edit;
std:: cout<<"Press 1 if you want to make changes to EMPLOYEE/CUSTOMER data.\n";
std:: cout<<"Press 2 if you want to make changes to CAR data. \n";
std::cin>>to_edit;
if (std::cin.fail()) {
std:: cout << "Failed reading number, Try again." << endl;
return 1;
}
if(to_edit==1){
int query;
std:: cout<<"Press 1 if you want to make changes to CUSTOMER data.\n";
std:: cout<<"Press 2 if you want to make changes to EMPLOYEE data. \n";
std::cin>>query;
if (std::cin.fail()) {
std:: cout << "Failed reading number, Try again." << endl;
return 1;
}
if(query == 1){
Manager m;
std:: cout<<"Press 1 to add new customer.\n";
std:: cout<<"Press 2 to delete an existing customer.\n";
std:: cout<<"Press 3 to update a customer record.\n";
std:: cout<<"Press 4 to see list of all updated customers.\n";
int fun;
std::cin>>fun;
if (std::cin.fail()) {
std:: cout << "Failed reading number, Try again." << endl;
return 1;
}
if(fun == 1){
std:: cout<<"Enter the name of the customer.\n";
string name;
std::cin>>name;
m.add_customer(name);
std:: cout<<"Press 0 to exit else Press any digit.\n";
std::cin>>t;
if (std::cin.fail()) {
std:: cout << "Failed reading number, Try again." << endl;
return 1;
}
}
else if(fun == 2){
std:: cout<<"Enter the ID of the customer you want to delete.\n";
int del_id;
std::cin>>del_id;
m.delete_customer(del_id);
std:: cout<<"Customer acocunt deleted.\n";
std:: cout<<"Press 0 to exit else Press any digit.\n";
std::cin>>t;
if (std::cin.fail()) {
std:: cout << "Failed reading number, Try again." << endl;
return 1;
}
}
else if(fun == 3){
std:: cout<<"Enter the ID of the customer you want to update records.\n";
int cus_id;
std::cin>>cus_id;
if (std::cin.fail()) {
std:: cout << "Failed reading number, Try again." << endl;
return 1;
}
std:: cout<<"Enter the number of cars returned late.\n ";
int n_cars_late;
std::cin>>n_cars_late;
if (std::cin.fail()) {
std:: cout << "Failed reading number, Try again." << endl;
return 1;
}
while(n_cars_late--){
int cr_id;
string cr_name;
std:: cout<<"Enter the Car id.\n";
std::cin>>cr_id;
if (std::cin.fail()) {
std:: cout << "Failed reading number, Try again." << endl;
return 1;
}
std:: cout<<"Enter the date of return in ddmmyy format.\n";
std::cin>>cr_name;
if (std::cin.fail()) {
std:: cout << "Failed reading name, Try again." << endl;
return 1;
}
m.update_customer(cus_id,cr_id,cr_name);
std:: cout<<"Record for this car has been updated. Proceed Further.\n";
}
std:: cout<<"Press 0 to exit else Press any other digit.\n";
std::cin>>t;
if (std::cin.fail()) {
std:: cout << "Failed reading number, Try again." << endl;
return 1;
}
}
else if(fun==4){
m.list_customers();
std:: cout<<"Press 0 to exit else Press any other digit.\n";
std::cin>>t;
if (std::cin.fail()) {
std:: cout << "Failed reading number, Try again." << endl;
return 1;
}
}
}
else if(query == 2){
Manager m;
std:: cout<<"Press 1 to add new employee.\n";
std:: cout<<"Press 2 to delete an existing employee.\n";
std:: cout<<"Press 3 to update a employee record.\n";
std:: cout<<"Press 4 to see the updated employee list.\n";
int fun;
std::cin>>fun;
if (std::cin.fail()) {
std:: cout << "Failed reading number, Try again." << endl;
return 1;
}
if(fun == 1){
std:: cout<<"Enter the name of the employee.\n";
string name;
std::cin>>name;
m.add_employee(name);
std:: cout<<"Press 0 to exit else Press any digit.\n";
std::cin>>t;
if (std::cin.fail()) {
std:: cout << "Failed reading number, Try again." << endl;
return 1;
}
}
else if(fun == 2){
std:: cout<<"Enter the ID of the employee you want to delete.\n";
int del_id;
std::cin>>del_id;
if (std::cin.fail()) {
std:: cout << "Failed reading number, Try again." << endl;
return 1;
}
m.delete_employee(del_id);
std:: cout<<"Employee account deleted.\n";
std:: cout<<"Press 0 to exit else Press any digit.\n";
std::cin>>t;
if (std::cin.fail()) {
std:: cout << "Failed reading number, Try again." << endl;
return 1;
}
}
else if(fun == 3){
std:: cout<<"Enter the ID of the EMPLOYEE you want to update records.\n";
int emp_id;
std::cin>>emp_id;
if (std::cin.fail()) {
std:: cout << "Failed reading number, Try again." << endl;
return 1;
}
std:: cout<<"Enter the number of cars returned late.\n ";
int n_cars_late;
std::cin>>n_cars_late;
if (std::cin.fail()) {
std:: cout << "Failed reading number, Try again." << endl;
return 1;
}
while(n_cars_late--){
int cr_id;
string cr_name;
std:: cout<<"Enter the Car id.\n";
std::cin>>cr_id;
if (std::cin.fail()) {
std:: cout << "Failed reading number, Try again." << endl;
return 1;
}
std:: cout<<"Enter the date of return in ddmmyy format.\n";
std::cin>>cr_name;
if (std::cin.fail()) {
std:: cout << "Failed reading number, Try again." << endl;
return 1;
}
m.update_employee(emp_id,cr_id,cr_name);
std:: cout<<"Record for this car has been updated. Proceed Further.\n";
}
std:: cout<<"Press 0 to exit else Press any other digit.\n";
std::cin>>t;
if (std::cin.fail()) {
std:: cout << "Failed reading number, Try again." << endl;
return 1;
}
}
else if(fun == 4){
m.list_employees();
std:: cout<<"Press 0 to exit else Press any other digit.\n";
std::cin>>t;
if (std::cin.fail()) {
std:: cout << "Failed reading number, Try again." << endl;
return 1;
}
}
}
}
else if(to_edit == 2){
std:: cout<<"Press 1 if you want to add a car to CARS database.\n";
std:: cout<<"Press 2 if you want to delete a car from CARS database.\n";
std:: cout<<"Press 3 if you want to update a car information.\n";
int operation;
std::cin>>operation;
if(operation == 1){
string car_name;
std:: cout<<"Enter the name of the car you want the add.\n";
std::cin>>car_name;
if (std::cin.fail()) {
std:: cout << "Failed reading number, Try again." << endl;
return 1;
}
string date;
std:: cout<<"Enter date from which it will be availaible to rent out in ddmmyy format.\n";
std::cin>>date;
if (std::cin.fail()) {
std:: cout << "Failed reading number, Try again." << endl;
return 1;
}
int rent_price;
std:: cout<<"Enter the rental price per day of the car.\n";
std::cin>>rent_price;
if (std::cin.fail()) {
std:: cout << "Failed reading number, Try again." << endl;
return 1;
}
Manager m;
m.add_car(car_name,rent_price,date);
std:: cout<<"Press 0 to exit else Press any other digit.\n";
std::cin>>t;
if (std::cin.fail()) {
std:: cout << "Failed reading number, Try again." << endl;
return 1;
}
}
else if(operation == 2){
int car_number;
std:: cout<<"Enter the number of the car you want to delete.\n";
Manager m;
m.delete_car(car_number);
std:: cout<<"Press 0 to exit else Press any other digit.\n";
std::cin>>t;
if (std::cin.fail()) {
std:: cout << "Failed reading number, Try again." << endl;
return 1;
}
}
else if(operation == 3){
int car_number;
int new_rent_price;
string new_availaibility_date;
std:: cout<<"Enter the number of the car you want to update.\n";
std::cin>>car_number;
if (std::cin.fail()) {
std:: cout << "Failed reading number, Try again." << endl;
return 1;
}
std:: cout<<"Enter the new rental price of the car.\n";
std::cin>>new_rent_price;
if (std::cin.fail()) {
std:: cout << "Failed reading number, Try again." << endl;
return 1;
}
std:: cout<<"Enter the updated date of availaibility of the car.\n";
std::cin>>new_availaibility_date;
if (std::cin.fail()) {
std:: cout << "Failed reading number, Try again." << endl;
return 1;
}
Manager m;
m.update_car(car_number,new_rent_price,new_availaibility_date);
}
}
}
}
else if(role==3){
std:: cout<<"Please enter your Employee ID.\n";
int Employee_ID;
std::cin>>Employee_ID;
if (std::cin.fail()) {
std:: cout << "Failed reading number, Try again." << endl;
return 1;
}
if(Employee_ID>=EMPLOYEE.size()){
"You are not a validated EMPLOYEE.\n";
}
else{
std:: cout<<"How can we help you?\n";
std:: cout<<"Press 1 to see menu.\n";
int menu;
std::cin>>menu;
if (std::cin.fail()) {
std:: cout << "Failed reading number, Try again." << endl;
return 1;
}
while(menu){
std:: cout<<"Press 1 if you want to see the availaible cars.\n"<<"Press 2 if you want to see your fine dues.\n"<<"Press 3 if you want to see cars you have rented out.\n"<<"Press 4 if you want to rent a car.\n";
int enquiry;
std::cin>>enquiry;
if (std::cin.fail()) {
std:: cout << "Failed reading number, Try again." << endl;
return 1;
}
if(enquiry == 1){
Employee c;
c.id = Employee_ID;
c.see_cars();
int forward;
std:: cout<<"Press 0 to exit, to continue Press any digit.\n";
std::cin>>forward;
if (std::cin.fail()) {
std:: cout << "Failed reading number, Try again." << endl;
return 1;
}
menu = forward;
}
else if(enquiry == 2){
Employee c;
c.id = Employee_ID;
c.Fine_dues(Employee_ID);
int forward;
std:: cout<<"Press 0 to exit, to continue Press any digit. \n";
std::cin>>forward;
if (std::cin.fail()) {
std:: cout << "Failed reading number, Try again." << endl;
return 1;
}
menu = forward;
}
else if(enquiry == 3){
Employee c;
c.id = Employee_ID;
c.Rented_Cars(Employee_ID);
int forward;
std:: cout<<"Press 0 to exit, to continue Press any digit.\n";
std::cin>>forward;
if (std::cin.fail()) {
std:: cout << "Failed reading number, Try again." << endl;
return 1;
}
menu = forward;
}
else if(enquiry == 4){
Employee c;
c.id = Employee_ID;
c.rent_car();
int forward;
std:: cout<<"Press 0 to exit, to continue Pressany digit. \n";
std::cin>>forward;
if (std::cin.fail()) {
std:: cout << "Failed reading number, Try again." << endl;
return 1;
}
menu = forward;
}
else{
std:: cout<<"Enter a valid input\n";
int forward;
std:: cout<<"Press 0 to exit, to continue Press any digit. \n";
std::cin>>forward;
if (std::cin.fail()) {
std:: cout << "Failed reading number, Try again." << endl;
return 1;
}
menu = forward;
}
}
}
}
else{
std:: cout<<"Enter a valid input.\n";
continue;
}
std:: cout<<"If you want to exit PRESS 0, to re-enter to the system press any digit.\n";
std::cin>>stay;
if (std::cin.fail()) {
std:: cout << "Failed reading number, Try again." << endl;
return 1;
}
}
return 0;
}