-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
361 lines (348 loc) · 14.1 KB
/
main.cpp
File metadata and controls
361 lines (348 loc) · 14.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
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
#include <vector>
using std::vector;
#include "Vehicle.h"
#include "Car.h"
#include "Hybrid.h"
#include "Motor.h"
#include "Bus.h"
#include "Structure.h"
int main()
{
// Creates structure.
Structure< Vehicle > *a = new Structure< Vehicle >;
a->MLH_set_print_option(0);
int choice = 0;
int task = 0;
int t;
int input = 0;
int id, year, mileage;
int engine, poll, battery;
string gas;
string color;
string service;
Vehicle *v;
// Variable specifications.
int front, back, passenger;
int powerful;
int usage;
int pa, la;
int init = 0;
while (init != 4)
{
cout << ":::::::600.120 Car Center Main Page::::::" << endl;
cout << "Do you want to: 1.add a vehicle 2.add tasks 3.checkout/print/ohers 4.bye" <<endl;
cin>>init;
//switches choice.
switch (init)
case 1:
while (choice != 5)
{
cout << "Enter int id --->" << endl;
cin >> id;
cout << "Enter int year Eg.1949 --->" << endl;
cin >> year;
cout << "Enter int mileage --->" << endl;
cin >> mileage;
cout << "Enter string color ---> Eg.Pink" << endl;
cin >> color;
cout << "Choose a vehicle: " << endl;
cout << "1.car 2.hybrid 3.motor 4.bus 5.stop adding" << endl;
cin >> choice;
//swiches vehicle selection.
switch (choice)
{
case 1:
{
cout << "Enter int engine --->" << endl;
cin >> engine;
cout << "Enter string gas(premium/plus/regular) --->" << endl;
cin >> gas;
cout << "Enter pollution level(int 1-5) --->" << endl;
cin >> poll;
//allocates space for a new car.
v = new Car(id, year, color, mileage, engine, gas, poll);
a->MLH_insert(id, v);
cout << "The car is added! \n";
break;
}
case 2:
{
//Creating hybrid.
cout << "Enter int engine --->" << endl;
cin >> engine;
cout << "Enter string gas(premium/plus/regular) --->" << endl;
cin >> gas;
cout << "Enter pollution level(int 1-5) --->" << endl;
cin >> poll;
cout << "Enter int overall usage --->" << endl;
cin >> usage;
cout << "Enter int motor power --->" << endl;
cin >> powerful;
cout << "Enter int Battery capacity --->" << endl;
cin >> battery;
v = new Hybrid(id, year, color, mileage, engine, gas, poll, powerful, usage, battery);
a->MLH_insert(id, v);
cout << "The hybrid is added! \n";
break;
}
case 3:
{
//Creating motor.
cout << "Enter int engine --->" << endl;
cin >> engine;
cout << "Enter int front wheel size---> " << endl;
cin >> front;
cout << "Enter int back wheel size--->" << endl;
cin >> back;
v = new Motor(id, year, color, mileage, engine, front, back);
a->MLH_insert(id, v);
cout << "The motor is added! \n";
break;
}
case 4:
{
//Creating bus.
cout << "Enter int passenger capacity --->" << endl;
cin >> passenger;
v = new Bus(id, year, color, mileage, passenger);
a->MLH_insert(id, v);
cout << "The bus is added! \n";
break;
}
default:
{
cout << "Stop adding/ Invalid selection! "<< endl;
break;
}
}
/* Setting choice to previous value.*/
choice = 0;
break;
case 2:
while (task != 6)
{
cout << "Choose a task: 1.maintanance 2.brake change 3.tune_up 4.wash 5.decoration 6.stop adding task" << endl;
cin >> task;
// Switches task among 5 options.
switch (task)
{
case 1:
{
cout << "Indicate cost of parts--->" << endl;
cin >> pa;
cout << "Indicate cost of labors--->" << endl;
cin >> la;
cout << "Which vehicle to insert a task? Indicate int id here:\n";
cin >> id;
Vehicle *g = a->MLH_get(id);
if (g == NULL)
{
cout << "the vehicle doesn not exist! \n";
break;
}
service = "maintanance";
// Creates a task and wrap it as a node, inserting
g->add(service, pa, la);
cout<<"Task added!\n";
g = NULL;
break;
}
case 2:
{
cout << "Indicate cost of parts--->" << endl;
cin >> pa;
cout << "Indicate cost of labors--->" << endl;
cin >> la;
cout << "Which vehicle to insert a task? Indicate id here:\n";
cin >> id;
Vehicle *g = a->MLH_get(id);
if (g == NULL)
{
cout << "the vehicle doesn not exist! \n";
break;
}
service = "brake change";
a->MLH_get(id)->add(service, pa, la);
cout<<"Task added!\n";
g = NULL;
break;
}
case 3:
{
service = "tune_up";
cout << "Indicate cost of parts--->" << endl;
cin >> pa;
cout << "Indicate cost of labors--->" << endl;
cin >> la;
cout << "Which vehicle to insert a task? Indicate id here:" << endl;
cin >> id;
Vehicle *g = a->MLH_get(id);
if (g == NULL)
{
cout << "the vehicle doesn not exist! \n";
break;
}
a->MLH_get(id)->add(service, pa, la);
cout<<"Task added!\n";
g = NULL;
break;
}
case 4:
{
cout << "Indicate cost of parts--->" << endl;
cin >> pa;
cout << "Indicate cost of labors--->" << endl;
cin >> la;
cout << "Which vehicle to insert a task? Indicate id here:" << endl;
cin >> id;
Vehicle *g = a->MLH_get(id);
if (g == NULL)
{
cout << "the vehicle doesn not exist! \n";
break;
}
service = "wash";
a->MLH_get(id)->add(service, pa, la);
cout<<"Task added!\n";
g = NULL;
break;
}
case 5:
{
cout << "Indicate cost of parts--->" << endl;
cin >> pa;
cout << "Indicate cost of labors--->" << endl;
cin >> la;
cout << "Which vehicle to insert a task? Indicate id here:" << endl;
cin >> id;
Vehicle *g = a->MLH_get(id);
if (g == NULL)
{
cout << "the vehicle doesn not exist! \n";
break;
}
service = "decoration";
a->MLH_get(id)->add(service, pa, la);
cout<<"Task added!\n";
g = NULL;
break;
}
default:
{
cout << "Stop adding/ Invalid task selection! \n";
break;
}
}
}
task = 0;
break;
case 3:
while (input != 6)
{
cout << "1.Checkout a vehicle" << endl;
cout << "2.View all vehicles" << endl;
cout << "3.View single vehicle" << endl;
cout << "4.Check the current bill of the car" << endl;
cout << "5.Paint a car (change car color)" << endl;
cout << "6.Exit check/view" << endl;
cin >> input;
switch (input)
{
//switches selection.
case 1:
{
cout << "Enter the vehicle id to checkout" << endl;
//gets a vehicle
cin >> id;
//vehicle pointer created
Vehicle *m = a->MLH_get(id);
if (m == NULL)
{ //vehicle not found.
cout << "the vehicle doesn not exist! \n";
break;
}
m->printbill();
//deletes the vehicle.
m = a->MLH_delete(id);
cout << "Vehicle deletion complete!\n";
//nullifies pointer
m = NULL;
break;
}
case 2:
{
cout << "Viewing all the vehicles>>>" << endl;
//prints entire structure.
cout << *a;
break;
}
case 3:
{
cout << "Which vehicle to view?" << endl;
cin >> id;
Vehicle *n = a->MLH_get(id);
if (n == NULL)
{
cout << "the vehicle doesn not exist! \n";
break;
}
//prints vehicle infomation by calling overloaded operator.
cout << *n;
n = NULL;
break;
}
case 4:
{
cout << "Which vehicle to view bill, enter id?" << endl;
cin >> id;
Vehicle *n = a->MLH_get(id);
if (n == NULL)
{
cout << "the vehicle doesn not exist! \n";
break;
}
//get sum of costs in the tasklist.
cout << "Total cost so far is: $"<<n->getcost() << endl;
n = NULL;
break;
}
case 5:
{
cout << "Which vehicle paint, enter id?" << endl;
cin >> id;
Vehicle *n = a->MLH_get(id);
if (n == NULL)
{
cout << "the vehicle doesn not exist! \n";
break;
}
cout << "Change to which color? " << endl;
cin >> color;
//changes vehicle color string representation.
n->setcolor(color);
cout << "Vehicle No. "<< id << "Is changed to "<< color << "!" << endl;
n = NULL;
break;
}
default:
{
cout << "Exiting this level of menu for invalid selection/ Quitting" << endl;
break;
}
}
}
//restores input, in case of infinite loop.
input = 0;
break;
}
}
cout<< "Byebye! Thank you for visiting!" << endl;
//deletes a.
delete a;
a = NULL;
return 0;
}