-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
350 lines (309 loc) · 7.36 KB
/
main.cpp
File metadata and controls
350 lines (309 loc) · 7.36 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
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
// Define constants
const double TICKET_PRICE = 5000.0;
const int TICKET_VALIDITY_YEARS = 10;
const int MAX_TRAVELLERS = 10;
const int MAX_TRAVELS = 100;
// Define Planet class
class Planet
{
private:
string name;
double x, y, z;
public:
Planet(string name, double x, double y, double z)
{
this->name = name;
this->x = x;
this->y = y;
this->z = z;
}
string getName()
{
return name;
}
double getX()
{
return x;
}
double getY()
{
return y;
}
double getZ()
{
return z;
}
void setName(string name)
{
this->name = name;
}
void setX(double x)
{
this->x = x;
}
void setY(double y)
{
this->y = y;
}
void setZ(double z)
{
this->z = z;
}
vector<double> getCoordinates()
{
return {x, y, z};
}
};
// Define Ticket class
class Ticket
{
private:
int id;
string source;
string destination;
string travellerName;
int travellerId;
int validityYears;
bool isReturnTicket;
double price;
int daysUntilTravel;
public:
Ticket(int id, string source, string destination, string travellerName, int travellerId, bool isReturnTicket, int daysUntilTravel)
{
this->id = id;
this->source = source;
this->destination = destination;
this->travellerName = travellerName;
this->travellerId = travellerId;
this->validityYears = TICKET_VALIDITY_YEARS;
this->isReturnTicket = isReturnTicket;
this->price = TICKET_PRICE / (daysUntilTravel + 1);
this->daysUntilTravel = daysUntilTravel;
}
bool isValid()
{
return validityYears > 0;
}
void updateValidity(int years)
{
validityYears += years;
}
void printTicketDetails()
{
cout << "Ticket ID: " << id << endl;
cout << "Traveller Name: " << travellerName << endl;
cout << "Traveller ID: " << travellerId << endl;
cout << "Source Planet: " << source << endl;
cout << "Destination Planet: " << destination << endl;
cout << "Is Return Ticket: " << (isReturnTicket ? "Yes" : "No") << endl;
cout << "Validity Years: " << validityYears << endl;
cout << "Price: " << price << endl;
cout << "Days Until Travel: " << daysUntilTravel << endl;
}
string getSource()
{
return this->source;
}
string getDestination()
{
return this->destination;
}
int getDays()
{
return this->daysUntilTravel;
}
};
// Define Traveller class
class Traveller
{
protected:
string name;
int id;
public:
Traveller(string name, int id)
{
this->name = name;
this->id = id;
}
string getName()
{
return name;
}
int getId()
{
return id;
}
void setName(string name)
{
this->name = name;
}
void setId(int id)
{
this->id = id;
}
};
// Define Astronaut class
class Astronaut : public Traveller
{
private:
int yearsOfExperience;
string licenseId;
public:
Astronaut(string name, int id, int yearsOfExperience, string licenseId) : Traveller(name, id)
{
this->yearsOfExperience = yearsOfExperience;
this->licenseId = licenseId;
}
void setYears(int years)
{
this->yearsOfExperience = years;
}
void setLincence(int licenceId)
{
this->licenseId = licenceId;
}
};
// Define Commander class
class Commander : public Traveller
{
private:
string authority;
public:
Commander(string name, int id, string authority) : Traveller(name, id)
{
this->authority = authority;
}
void setAuthority(string authority)
{
this->authority = authority;
}
};
class SpaceTravel
{
private:
vector<Ticket> tickets;
vector<Traveller *> travellers;
int nextTicketId;
int nextTravellerId;
int nextPlanetId;
public:
SpaceTravel()
{
nextTicketId = 1;
nextTravellerId = 1;
nextPlanetId = 1;
}
void addtraveller(Traveller *t)
{
travellers.push_back(t);
nextTravellerId++;
}
void addTickets(Ticket t)
{
tickets.push_back(t);
nextTicketId++;
}
void listTravellers()
{
cout << "Travellers:" << endl;
for (auto traveller : travellers)
{
cout << traveller->getName() << endl;
}
}
Traveller *findTraveller(int id)
{
for (auto &traveller : travellers)
{
if (traveller->getId() == id)
{
return traveller;
}
}
return nullptr;
}
void listTickets()
{
cout << "Tickets:" << endl;
for (auto ticket : tickets)
{
ticket.printTicketDetails();
}
}
void expireTickets(int years)
{
for (auto &ticket : tickets)
{
ticket.updateValidity(-years);
}
}
};
int main()
{
Planet earth("Earth", 0, 0, 0);
Planet mars("Mars", 50, 50, 50);
Planet venus("Venus", -30, 20, -10);
vector<Planet> planets;
planets.push_back(earth);
planets.push_back(mars);
planets.push_back(venus);
Traveller p1("Alice", 1);
Traveller p2("Bob", 2);
Traveller p3("Charlie", 3);
Traveller p4("David", 4);
Traveller p5("Eve", 5);
Traveller p6("Frank", 6);
Traveller p7("Grace", 7);
Traveller p8("Harry", 8);
Traveller p9("Isaac", 9);
Traveller p10("John", 10);
Traveller p11("Kathe", 11);
vector<Traveller *> travellers;
Ticket t1(1, "Earth", "Mars", "Alice", 1, false, 5);
Ticket t2(2, "Earth", "Mars", "Bob", 2, false, 5);
Ticket t3(3, "Earth", "Mars", "Charlie", 3, false, 5);
Ticket t4(4, "Earth", "Mars", "David", 4, false, 5);
vector<Ticket> tickets;
tickets.push_back(t1);
tickets.push_back(t2);
tickets.push_back(t3);
tickets.push_back(t4);
// Checking validity for the passengers p1-p4 if they have the same source and destination on the same day
if (t1.getSource() == "Earth" && t1.getDestination() == "Mars" && t1.getDays() == 5)
travellers.push_back(&p1);
if (t2.getSource() == "Earth" && t2.getDestination() == "Mars" && t2.getDays() == 5)
travellers.push_back(&p2);
if (t3.getSource() == "Earth" && t3.getDestination() == "Mars" && t3.getDays() == 5)
travellers.push_back(&p3);
if (t4.getSource() == "Earth" && t4.getDestination() == "Mars" && t4.getDays() == 5)
travellers.push_back(&p4);
Astronaut a1("Buzz Aldrin", 1, 30, "12345");
Astronaut a2("Neil Armstrong", 2, 20, "67890");
Commander c1("Chris Hadfield", 11, "NASA");
Commander c2("Yuri Gagarin", 12, "Roscosmos");
travellers.push_back(&a1);
travellers.push_back(&c1);
if (travellers.size() > 4)
{ // travellers must be greater than 4 because two of them are astronaut and commander
SpaceTravel s1;
for (auto traveller : travellers)
{
s1.addtraveller(traveller);
}
for (auto ticket : tickets)
{
s1.addTickets(ticket);
}
s1.listTravellers();
s1.listTickets();
}
else
{
cout << "Not Enough passengers";
}
return 0;
}