-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproject2.cpp
More file actions
197 lines (177 loc) · 5.26 KB
/
Copy pathproject2.cpp
File metadata and controls
197 lines (177 loc) · 5.26 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
#include <iostream>
#include <stdlib.h>
#include <ctime>
#include <windows.h>
#include "libs/loginacc.h"
#include "libs/register.h"
using namespace std;
class VehicleType
{
public:
virtual float calculateFair(float dist) = 0;
virtual ~VehicleType() {}
};
class MotoType : public VehicleType
{
float calculateFair(float dist) override
{
return (dist > 0 && dist <= 2) ? 40 : dist * 15;
}
};
class UberMiniType : public VehicleType
{
float calculateFair(float dist) override
{
return (dist > 0 && dist <= 2) ? 50 : dist * 25;
}
};
class UberGoType : public VehicleType
{
float calculateFair(float dist) override
{
return (dist > 0 && dist <= 2) ? 80 : dist * 30;
}
};
class Account : public Register, public login
{
char x;
float wallet;
public:
int setLogInSignUp()
{
system("COLOR d0");
input:
cout << "\t\t\t\t\t|------------------------------------------------------|" << endl;
cout << "\t\t\t\t\t| UBER | " << endl;
cout << "\t\t\t\t\t|------------------------------------------------------|" << endl;
cout << "\t\t\t\t\t| Press L for Login or S for Sign up |" << endl;
cout << "\t\t\t\t\t|------------------------------------------------------|" << endl;
cout << "\t\t\t\t\t|";
cin >> x;
if (x == 's' || x == 'S')
{
Register::set_name();
Register::set_age();
Register::set_email();
Register::set_password();
}
else if (x == 'l' || x == 'L')
{
check:
login::setlogin_email();
login::setlogin_password();
if (login::getlogin_email() == Register::get_email() && login::getlogin_password() == Register::get_password())
{
cout << "\t\t\t\t\t|-------------------Login successfuly!-----------------| " << endl;
}
else
{
cout << "\t\t\t\t\t|---------- Wrong id or password! ----------|" << endl;
Beep(2000, 500);
goto check;
}
}
else
{
cout << "\t\t\t\t\t|------------- Wrong choice --------------|" << endl;
goto input;
}
return 0;
}
void walletamount()
{
cout << "\t\t\t\t\t|------------------------------------------------------|" << endl;
cout << "\t\t\t\t\t|PAID AMOUNT : ";
cin >> wallet;
}
float get_walletamount() { return wallet; }
};
class Ride : public Account
{
int vehicleChoice;
float distance, fair;
string pickup, drop;
VehicleType *vPtr = nullptr;
public:
int drivers_active() { return rand() % 10 + 1; }
void set_pickup()
{
cout << "\t\t\t\t\t|Enter Pickup Point : ";
cin >> pickup;
}
void set_drop()
{
cout << "\t\t\t\t\t|Enter Drop Point:";
cin >> drop;
}
float get_distance()
{
distance = rand() % 30 + 0.5;
return distance;
}
void set_vehicle()
{
cout << "\t\t\t\t\t|Enter 1 for Moto " << endl;
cout << "\t\t\t\t\t|Enter 2 for Uber Mini " << endl;
cout << "\t\t\t\t\t|Enter 3 for Uber Go " << endl;
cout << "\t\t\t\t\t|";
cin >> vehicleChoice;
if (vehicleChoice == 1)
vPtr = new MotoType();
else if (vehicleChoice == 2)
vPtr = new UberMiniType();
else if (vehicleChoice == 3)
vPtr = new UberGoType();
}
float get_fair()
{
if (vPtr)
{
fair = vPtr->calculateFair(get_distance());
return fair;
}
return 0;
}
void current_time()
{
time_t curr_time = time(NULL);
tm *tm_local = localtime(&curr_time);
cout << "\t\t\t\t\t|Current local time : " << tm_local->tm_hour << ":" << tm_local->tm_min << ":" << tm_local->tm_sec << "\t\t\t |" << endl;
}
void display_ride()
{
cout << "\t\t\t\t\t|ACTIVE DRIVERS NEAR YOU : " << drivers_active() << " |" << endl;
cout << "\t\t\t\t\t|TRIP DISTANCE : " << distance << " km |" << endl;
cout << "\t\t\t\t\t|FAIR : " << get_fair() << " pkr |" << endl;
cout << "\t\t\t\t\t|------------------------------------------------------|" << endl;
cout << "\t\t\t\t\t| RIDE END |" << endl;
}
float remainingbal() { return get_walletamount() - fair; }
void feedback()
{
int stars;
cout << "\t\t\t\t\t|HOW WAS YOUR EXPERIENCE (1-5): ";
cin >> stars;
cout << "\t\t\t\t\t|YOUR REMAINING AMOUNT : " << remainingbal() << endl;
delete vPtr;
}
};
int main()
{
srand((unsigned)time(0));
Ride U;
// Set user details according to your requirement
U.set_name("Asadullah");
U.set_password("AD123");
U.set_email("asad@gmail.com");
U.set_age(19);
U.setLogInSignUp();
U.set_pickup();
U.set_drop();
U.set_vehicle();
U.current_time();
U.display_ride();
U.walletamount();
U.feedback();
return 0;
}