-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgaragev1.cpp
More file actions
380 lines (329 loc) · 11.3 KB
/
Copy pathgaragev1.cpp
File metadata and controls
380 lines (329 loc) · 11.3 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
#include <iostream>
#include <fstream>
#include <string>
#define LINE_MAX 28
class Vehicle{
private:
std::string color;
std::string brand;
std::string hp;
std::string speedTop;
std::string wheels;
public:
void setColor( std::string color){ this->color = color; }
void setBrand( std::string brand){ this->brand = brand; }
void setHp( std::string hp){ this->hp = hp; }
void setSpeedTop( std::string speedTop){ this->speedTop = speedTop; }
void setWheels( std::string wheels){ this->wheels = wheels; }
void printCarStat() {
std::cout << "Color:" << color << '\n';
std::cout << "Brand:" << brand << '\n';
std::cout << "Hp:" << hp << '\n';
std::cout << "Top Speed:" << speedTop << '\n';
std::cout << "Number of wheels:" << wheels << '\n';
}
};
class Spot : public Vehicle{
private:
std::string firstName;
std::string secondName;
public:
void setFirstName(std::string firstName){this->firstName = firstName;}
void setSecondName(std::string secondName){this->secondName = secondName;}
void printOwnerID() {std::cout << "OwnerID:" << firstName.at(0) << secondName.at(0) << '\n';}
};
int main(){
//var spot a
std::string colorSpotA = "empty";
std::string brandSpotA = "empty";
std::string hpSpotA = "0";
std::string speedTopSpotA = "0";
std::string wheelsSpotA = "0";
std::string firstNameSpotA = "empty";
std::string secondNameSpotA = "empty";
//var spot b
std::string colorSpotB = "empty";
std::string brandSpotB = "empty";
std::string hpSpotB = "0";
std::string speedTopSpotB = "0";
std::string wheelsSpotB = "0";
std::string firstNameSpotB = "empty";
std::string secondNameSpotB = "empty";
//var spot c
std::string colorSpotC = "empty";
std::string brandSpotC = "empty";
std::string hpSpotC = "0";
std::string speedTopSpotC = "0";
std::string wheelsSpotC = "0";
std::string firstNameSpotC = "empty";
std::string secondNameSpotC = "empty";
//var spot d
std::string colorSpotD = "empty";
std::string brandSpotD = "empty";
std::string hpSpotD = "0";
std::string speedTopSpotD = "0";
std::string wheelsSpotD = "0";
std::string firstNameSpotD = "empty";
std::string secondNameSpotD = "empty";
//saving var
std::ifstream save;
std::string array[LINE_MAX];
//read save
save.open("save.txt");
if (save.fail()){
std::cout << "Failed to find save file, generating, restart the program.\n";
std::ofstream save_c("save.txt");
save_c.close();
std::ofstream save("save.txt");
save
<< colorSpotA << '\n'<< brandSpotA << '\n'<< hpSpotA << '\n'<< speedTopSpotA << '\n'<< wheelsSpotA << '\n'<< firstNameSpotA << '\n'<< secondNameSpotA << '\n'
<< colorSpotB << '\n'<< brandSpotB << '\n'<< hpSpotB << '\n'<< speedTopSpotB << '\n'<< wheelsSpotB << '\n'<< firstNameSpotB << '\n'<< secondNameSpotB << '\n'
<< colorSpotC << '\n'<< brandSpotC << '\n'<< hpSpotC << '\n'<< speedTopSpotC << '\n'<< wheelsSpotC << '\n'<< firstNameSpotC << '\n'<< secondNameSpotC << '\n'
<< colorSpotD << '\n'<< brandSpotD << '\n'<< hpSpotD << '\n'<< speedTopSpotD << '\n'<< wheelsSpotD << '\n'<< firstNameSpotD << '\n'<< secondNameSpotD;
return 1;
}
int line = 0;
while (!save.eof()){
getline(save, array[line]);
line++;
}
save.close();
//test read file
//for (int i = 0; i < line; i++){
//std::cout << array[i] << '\n';
//}
//read the array from save file to memory
colorSpotA = array[0];
brandSpotA = array[1];
hpSpotA = array[2];
speedTopSpotA = array[3];
wheelsSpotA = array[4];
firstNameSpotA = array[5];
secondNameSpotA = array[6];
colorSpotB = array[7];
brandSpotB = array[8];
hpSpotB = array[9];
speedTopSpotB = array[10];
wheelsSpotB = array[11];
firstNameSpotB = array[12];
secondNameSpotB = array[13];
colorSpotC = array[14];
brandSpotC = array[15];
hpSpotC = array[16];
speedTopSpotC = array[17];
wheelsSpotC = array[18];
firstNameSpotC = array[19];
secondNameSpotC = array[20];
colorSpotD = array[21];
brandSpotD = array[22];
hpSpotD = array[23];
speedTopSpotD = array[24];
wheelsSpotD = array[25];
firstNameSpotD = array[26];
secondNameSpotD = array[27];
//program loop
int quit = 0;
while (quit == 0)
{
Spot a;
a.setColor(colorSpotA);
a.setBrand(brandSpotA);
a.setHp(hpSpotA);
a.setSpeedTop(speedTopSpotA);
a.setWheels(wheelsSpotA);
a.setFirstName(firstNameSpotA);
a.setSecondName(secondNameSpotA);
//a.printOwnerID();
//a.printCarStat();
Spot b;
b.setColor(colorSpotB);
b.setBrand(brandSpotB);
b.setHp(hpSpotB);
b.setSpeedTop(speedTopSpotB);
b.setWheels(wheelsSpotB);
b.setFirstName(firstNameSpotB);
b.setSecondName(secondNameSpotB);
//b.printOwnerID();
//b.printCarStat();
Spot c;
c.setColor(colorSpotC);
c.setBrand(brandSpotC);
c.setHp(hpSpotC);
c.setSpeedTop(speedTopSpotC);
c.setWheels(wheelsSpotC);
c.setFirstName(firstNameSpotC);
c.setSecondName(secondNameSpotC);
//c.printOwnerID();
//c.printCarStat();
Spot d;
d.setColor(colorSpotD);
d.setBrand(brandSpotD);
d.setHp(hpSpotD);
d.setSpeedTop(speedTopSpotD);
d.setWheels(wheelsSpotD);
d.setFirstName(firstNameSpotD);
d.setSecondName(secondNameSpotD);
//c.printOwnerID();
//c.printCarStat();
//Vehicle v;
//v.setColor("Red");
//v.setBrand("Audi");
//v.setHp(400);
//v.setSpeedTop(242.5);
//v.setWheels(4);
//v.printCarStat();
//std::string uID;
//int login;
int spot;
std::cout << "******* welcome to the garage *******\n";
//std::cout << "The garage is currently empty\n";
std::cout << "To park a car Choose a spot(1-4)";
std::cin >> spot;
switch (spot)
{
case 1:
std::cout << "you chose spot 1\n";
if (colorSpotA == "empty"){
std::cout << "this spot is empty\n";
std::cout << "to park a vehicle fill in this form\n";
std::cout << "First name:";
std::cin >> firstNameSpotA;
std::cout << "Second name:";
std::cin >> secondNameSpotA;
std::cout << "Color:";
std::cin >> colorSpotA;
std::cout << "Brand:";
std::cin >> brandSpotA;
std::cout << "Hp:";
std::cin >> hpSpotA;
std::cout << "Top Speed:";
std::cin >> speedTopSpotA;
std::cout << "Number of wheels:";
std::cin >> wheelsSpotA;
std::cout << "You just parked\n";
std::cin.clear();
fflush(stdin);
}
else{
std::cout << "this spot is taken by:\n";
a.printOwnerID();
a.printCarStat();
}
break;
case 2:
std::cout << "you chose spot 2\n";
if (colorSpotB == "empty"){
std::cout << "this spot is empty\n";
std::cout << "to park a vehicle fill in this form\n";
std::cout << "First name:";
std::cin >> firstNameSpotB;
std::cout << "Second name:";
std::cin >> secondNameSpotB;
std::cout << "Color:";
std::cin >> colorSpotB;
std::cout << "Brand:";
std::cin >> brandSpotB;
std::cout << "Hp:";
std::cin >> hpSpotB;
std::cout << "Top Speed:";
std::cin >> speedTopSpotB;
std::cout << "Number of wheels:";
std::cin >> wheelsSpotB;
std::cout << "You just parked\n";
std::cin.clear();
fflush(stdin);
}
else{
std::cout << "this spot is taken by:\n";
b.printOwnerID();
b.printCarStat();
}
break;
case 3:
std::cout << "you chose spot 3\n";
if (colorSpotC == "empty"){
std::cout << "this spot is empty\n";
std::cout << "to park a vehicle fill in this form\n";
std::cout << "First name:";
std::cin >> firstNameSpotC;
std::cout << "Second name:";
std::cin >> secondNameSpotC;
std::cout << "Color:";
std::cin >> colorSpotC;
std::cout << "Brand:";
std::cin >> brandSpotC;
std::cout << "Hp:";
std::cin >> hpSpotC;
std::cout << "Top Speed:";
std::cin >> speedTopSpotC;
std::cout << "Number of wheels:";
std::cin >> wheelsSpotC;
std::cout << "You just parked\n";
std::cin.clear();
fflush(stdin);
}
else{
std::cout << "this spot is taken by:\n";
c.printOwnerID();
c.printCarStat();
}
break;
case 4:
std::cout << "you chose spot 4\n";
if (colorSpotD == "empty"){
std::cout << "this spot is empty\n";
std::cout << "to park a vehicle fill in this form\n";
std::cout << "First name:";
std::cin >> firstNameSpotD;
std::cout << "Second name:";
std::cin >> secondNameSpotD;
std::cout << "Color:";
std::cin >> colorSpotD;
std::cout << "Brand:";
std::cin >> brandSpotD;
std::cout << "Hp:";
std::cin >> hpSpotD;
std::cout << "Top Speed:";
std::cin >> speedTopSpotD;
std::cout << "Number of wheels:";
std::cin >> wheelsSpotD;
std::cout << "You just parked\n";
std::cin.clear();
fflush(stdin);
}
else{
std::cout << "this spot is taken by:\n";
d.printOwnerID();
d.printCarStat();
}
break;
default:
std::cout << "invalid spot\n";
break;
}
//save variables to file
std::ofstream save("save.txt");
save
<< colorSpotA << '\n'<< brandSpotA << '\n'<< hpSpotA << '\n'<< speedTopSpotA << '\n'<< wheelsSpotA << '\n'<< firstNameSpotA << '\n'<< secondNameSpotA << '\n'
<< colorSpotB << '\n'<< brandSpotB << '\n'<< hpSpotB << '\n'<< speedTopSpotB << '\n'<< wheelsSpotB << '\n'<< firstNameSpotB << '\n'<< secondNameSpotB << '\n'
<< colorSpotC << '\n'<< brandSpotC << '\n'<< hpSpotC << '\n'<< speedTopSpotC << '\n'<< wheelsSpotC << '\n'<< firstNameSpotC << '\n'<< secondNameSpotC << '\n'
<< colorSpotD << '\n'<< brandSpotD << '\n'<< hpSpotD << '\n'<< speedTopSpotD << '\n'<< wheelsSpotD << '\n'<< firstNameSpotD << '\n'<< secondNameSpotD;
}
/*
std::cout << "1. Login 2. Signup";
std::cin >> login;
switch (login)
{
case 1:
std::cout << "Enter uID\n";
std::cin >> uID;
break;
case 2:
default:
break;
}
*/
//std::cout << "to park your car enter your owner ID\n";
//std::cin >> uID;
return 0;
}