-
Notifications
You must be signed in to change notification settings - Fork 0
/
file.c++
441 lines (383 loc) · 17 KB
/
file.c++
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
#include <iostream>
#include<string>
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#define MAXCARS 3
#define MaxFines 30
#define MaxDrivers 50
using namespace std;
//structures
struct Date
{
int Day;
int Month;
int Year;
};
struct Fines
{
float FineValue;
string StreetName;
Date FineDate;
bool Paid = false;
};
struct Cars
{
int PlateNum;
string Model;
int PYear;
Fines Fine[MaxFines];
};
struct Drivers
{
string Name;
int licenseNum;
Cars OwnedCars[MAXCARS];
Date BirthDate;
}driver[MaxDrivers];
//Functions
void Violation( bool &IsCorrectPlateNumber)//violation recording function
{
int MaxSpeed, Speed;
cout << "enter the car plate number:";
Cars x;
cin >> x.PlateNum;
for (int i = 0; i < MaxDrivers; i++)
{
for (int j = 0; j < MAXCARS; j++)
{
if (x.PlateNum == driver[i].OwnedCars[j].PlateNum)//checking that plate number exists
{
IsCorrectPlateNumber = true;
cout << "enter the car speed:";
cin >> Speed;
cout << "enter the maximum speed for the street:";
cin >> MaxSpeed;
for (int k = 0; k < MaxFines; k++)
if (driver[i].OwnedCars[j].Fine[k].FineValue == 0)
{
cout << "enter the street name:";
cin.ignore();
getline(cin,driver[i].OwnedCars[j].Fine[k].StreetName);
driver[i].OwnedCars[j].Fine[k].FineValue = (Speed - MaxSpeed) * 2;
cout << "Enter Current day: ";
cin >> driver[i].OwnedCars[j].Fine[k].FineDate.Day;
cout << "Enter Current month: ";
cin >> driver[i].OwnedCars[j].Fine[k].FineDate.Month;
cout << "Enter Current year: ";
cin >> driver[i].OwnedCars[j].Fine[k].FineDate.Year;
k = MaxFines;
}
}
}
}
if (IsCorrectPlateNumber == false)
cout << "This plate number doesnot exist\n\n";//the plate number doesnt exist
}
void Driver_information_or_payment (bool &driverMenu, bool &Back ,int &i)
{
int counter2 = 0;
do
{
cout << "To add a new car information press(1)\nor view your registered cars and unpayed fines press(2): ";
int driverChoice;
cin >> driverChoice;
system("cls");
if (driverChoice == 1)
{
int counter3 = 0;
for (int j = 0; j < MAXCARS; j++)
{
if (driver[i].OwnedCars[j].PlateNum == 0)
{
counter3++;
cout << "Enter car plate num:";
cin >> driver[i].OwnedCars[j].PlateNum;
cout << "Enter car model: ";
cin.ignore();
getline(cin,driver[i].OwnedCars[j].Model);
cout << "Enter car production year:";
cin >> driver[i].OwnedCars[j].PYear;
j = MAXCARS;
}
if (j == MAXCARS - 1 && counter3 == 0)
{
cout << "Can't add more cars\nMax number of cars is 3!!\n\n";
}
}
}
else if (driverChoice == 2)
{
cout << "*your registered cars and their plate numbers*\n";
int TotalNumberOfFines = 0;
for (int j = 0; j < MAXCARS; j++)
{
if (driver[i].OwnedCars[j].PlateNum != 0)
cout << j + 1 << '-' << driver[i].OwnedCars[j].Model << ' ' << driver[i].OwnedCars[j].PlateNum << endl;
for ( int k = 0; k < MaxFines; k++)
if (driver[i].OwnedCars[j].Fine[k].FineValue != 0)
TotalNumberOfFines++;
} cout << endl << "Total number of fines: " << TotalNumberOfFines << endl;
if (TotalNumberOfFines > 0)//when fines are zero it goes to previous menu
{
cout << "To view fine for a specific car enter the car's plate number: ";
Cars x;
cin >> x.PlateNum;
int counter = 0;
for (int j = 0; j < MAXCARS; j++)
if (driver[i].OwnedCars[j].PlateNum == x.PlateNum)
{
for (int k = 0; k < MaxFines; k++)
{
if (driver[i].OwnedCars[j].Fine[k].FineValue != 0 && driver[i].OwnedCars[j].Fine[k].Paid == false)
{
counter++;
cout << k + 1 << '-' << "Fine value: " << driver[i].OwnedCars[j].Fine[k].FineValue << endl;
cout << "Fine date: " << driver[i].OwnedCars[j].Fine[k].FineDate.Day << '/' <<
driver[i].OwnedCars[j].Fine[k].FineDate.Month << '/' << driver[i].OwnedCars[j].Fine[k].FineDate.Year << endl;
cout << "Fine on street: " << driver[i].OwnedCars[j].Fine[k].StreetName << endl;
}
if (k == MaxFines - 1 && counter > 0)
{
bool isfinenumber = false;
while (isfinenumber == false)
{
cout << "If you want to pay a fine enter its number \n or press(0)for more: ";
int finenumber;
cin >> finenumber;
system("cls");
if (driver[i].OwnedCars[j].Fine[finenumber - 1].FineValue != 0 && finenumber != 0)
{
isfinenumber = true;
cout << "Your fine has been paid!!\n\n";
driver[i].OwnedCars[j].Fine[finenumber - 1].Paid = true;
driver[i].OwnedCars[j].Fine[finenumber - 1].FineValue = 0;
k = MaxFines;
}
else if (finenumber > counter)
cout << "Fine number does not exist!!" << endl;
else if (finenumber == 0)
{
isfinenumber = true;
Back = true;
system("cls");
}
}
}
}
}
} if (TotalNumberOfFines == 0)
{
cout << "There's no fines for this car!!\n\n";
}//when fines are zero it goes to previous menu
}
cout << "To sign out of your account press(1) \nTo go back to driver's options menu press(2) \nTo exit to main menu press(3): ";
int driverSignOut;
cin >> driverSignOut;
if (driverSignOut == 1)
{
Back = true;
driverMenu = false;
system("cls");
}
else if (driverSignOut == 2)
{
Back = false;
system("cls");
}
else if (driverSignOut == 3)
{
Back = true;
driverMenu = true;
system("cls");
}
} while (Back == false);
}
int main(){
//Drivers samples
Drivers driver1 = { "zack",456,
{
{784,"kia cerato",2012, { { 100 ,"90's street", {5,8,2014} } ,{} } }//fines
,{655,"BMW X6",2018, { { 50 ,"el tayaran street", {11,2,2020} }, {} ,{} } }
,{153,"Renault logan",2015, { { 200 ,"el nozha street", {20,6,2016} } ,{} ,{} } }
}
,{15,6,1999}
};
Drivers driver2={ "sam",114,
{
{417,"BMW X3",2017,{ { 70,"makram ebeid street",{19,10,2019} },{},{}} }//fines
,{174,"chevorlet lanos",2013,{ { 200,"abo bakr el sedek street",{19,10,2017} },{},{}} }
,{}//cars
}
,{9,11,1980}
};
Drivers driver3={ "malcom",963,
{
{239,"nissan sunny",2016,{ { 80,"othman ebn afan street",{19,10,2018}},{},{} } }//fines
,{}//carss
,{}
}
,{21,8,1990}
};
driver[0] = driver1;
driver[1] = driver2;
driver[2] = driver3;
char input = 'f';
while (input != 'l') //system is open
{
system("color F0");
//MAIN MENU:
cout << "\nWelcome to the traffic control system\n\n";
cout << "For traffic men adding fines press(1)\nFor driver's menu and fine payment press(2): ";
int press;
cin >> press;
system("cls");
if (press == 1)//TRAFFIC MAN MENU:
{
cout << "*Traffic man menu*\n\n";
bool trafficManMenu = false;
while (trafficManMenu == false)//entering traffic man menu
{
bool IsCorrectPlateNumber = false;
while (IsCorrectPlateNumber == false)
{
//violation function:
Violation(IsCorrectPlateNumber);
} //end of function
cout << "If you want to enter another fine press(y)\nor exit to the main menu press(n): ";//enter another fine or main menu
char key;
cin >> key;
if (key == 'y' || key == 'Y')
{
trafficManMenu = false;
system("cls");
}
else if (key == 'n' || key == 'N')
{
system("cls");
trafficManMenu = true;
}
}
}
else if (press == 2)//DRIVER MENU
{
string dname;
Drivers d;
bool driverMenu = false;
while (driverMenu == false)
{
int DriverPress = 0;
cout << "If you are already registered on this system and you want to sign in press(1)\nIf you're new and signing up press(2): ";
cin >> DriverPress;
system("cls");
if (DriverPress == 1)//signIn
{
int counter2 = 0;
cout << "*Driver's menu and fine payment*\n\n";
cout << "Please enter your license number: ";
cin >> d.licenseNum;
cout << "Enter your name: ";
cin.ignore();
getline(cin, dname);
//driver sign in with correct license number and name
for (int i = 0; i < MaxDrivers; i++)
{
if (driver[i].licenseNum == d.licenseNum)
if ( driver[i].Name == dname)
{
//function (I,J)
counter2++;
bool Back = false;
{
Driver_information_or_payment(driverMenu, Back, i);
i = MaxDrivers;
}
}
} if (counter2 == 0)
{
cout << "INCORRECT license number or name!!\n\n";
}
}
if (DriverPress == 2)//signUp
{
int CurrentDriverIndex;
for (int i = 0; i < MaxDrivers; i++)
{
if (driver[i].licenseNum == 0)
{
CurrentDriverIndex = i;
cout << "Add driver's name: ";
cin.ignore();
getline(cin, driver[i].Name);
cout << "Add driver's birthdate: \n(Day): ";
cin >> driver[i].BirthDate.Day;
cout << "(Month): ";
cin >> driver[i].BirthDate.Month;
cout << "(Year): ";
cin >> driver[i].BirthDate.Year;
bool IsLicenseTaken = false;
while (IsLicenseTaken == false)
{
cout << "\nAdd your license number: ";
int licenseNum;
cin >> licenseNum;
IsLicenseTaken = true;
for (int j = 0; j < MaxDrivers; j++)
if (licenseNum == driver[j].licenseNum)
IsLicenseTaken = false;
if (IsLicenseTaken == false)
cout << "This license number is already taken\nPlease enter another one ";
else if (IsLicenseTaken == true)//to save the lisence number:
{
driver[i].licenseNum = licenseNum;
i = MaxDrivers;
}
}
//driver can't sign up more than 3 cars
bool carSignup = false;
int k = 0;
do
{
if (k < 2)
{
cout << "Add your car plate number: ";
cin >> driver[CurrentDriverIndex].OwnedCars[k].PlateNum;
cout << "Add car production year: ";
cin >> driver[CurrentDriverIndex].OwnedCars[k].PYear;
cout << "Add car model: ";
cin.ignore();
getline(cin,driver[CurrentDriverIndex].OwnedCars[k].Model);
cout << "If you want to enter another car press(y)\n If not press(n)";
char anotherCar;
cin >> anotherCar;
if (anotherCar == 'y' || anotherCar == 'Y')
{
carSignup = false;
k++;
}
else if (anotherCar == 'n' || anotherCar == 'N')
carSignup = true;
}
else if (k == 2)
{
cout << "enter your car plate number: ";
cin >> driver[CurrentDriverIndex].OwnedCars[k].PlateNum;
cout << "enter car production year: ";
cin >> driver[CurrentDriverIndex].OwnedCars[k].PYear;
cout << "enter car model: ";
cin >> driver[CurrentDriverIndex].OwnedCars[k].Model;
cout << "Max number of cars is 3\n\n ";
carSignup = true;
}
} while (carSignup == false);
}
}//function (current driver index ,J)
bool Back = false;
Driver_information_or_payment( driverMenu, Back, CurrentDriverIndex);
//end of function
}
}
}
}
return 0;
}