forked from Latasha123/Car-Parking-Management-System
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcarparking.cpp
303 lines (292 loc) · 7.85 KB
/
carparking.cpp
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
#include<iostream>
#include<ctime>
#include<vector>
using namespace std;
static int count = 0;
class Customer
{
string name;
string phone;
public:
Customer()
{
cin.ignore();
cout<<"Enter name: ";
getline(cin,name);
cout<<"Enter phone number: ";
getline(cin,phone);
}
string getName()
{
return name;
}
string getPhone()
{
return phone;
}
};
class Vehicle:public Customer
{
string carNo;
int slotNo, ticketNo, billNo, charges;
time_t entryTime, exitTime;
public:
void getTicket(int slot)
{
slotNo=slot;
cout<<"Enter car number: ";
getline(cin,carNo);
entryTime = time(0);
count++;
string t = ctime(&entryTime);
ticketNo = count;
system("cls"); // To clear the screen in Visual C++ ,utilize the code
displayTicket();
}
void displayTicket()
{
cout<<"******** XYZ CAR PARKING TICKET ********";
cout<<"\n\nTicket number: "<<ticketNo;
cout<<"\nCar Number: "<<carNo;
cout<<"\nEntry Time: "<<ctime(&entryTime);
cout<<"\nParking Spot: "<<slotNo;
cout<<"\nCurrent Status: UNPAID";
cout<<"\n\nEnter any key to go back to main menu..";
char c = getchar();
system("cls");
}
void getBill()
{
exitTime = time(0);
billNo = ticketNo;
calculateCharges();
}
int getTicketNo()
{
return ticketNo;
}
int getSlot()
{
return slotNo;
}
void calculateCharges()
{
long long duration = exitTime-entryTime;
int mins = duration/60;
int hours = mins/60;
int extra_min = mins%60;
if(hours==0 && extra_min<=30)
charges = 20;
else if(hours<=2 && extra_min==0)
charges = 55;
else if(hours<=7)
charges = 55 + (hours-2)*10;
else
charges = 165;
displayBill();
}
void displayBill()
{
cout<<"******** XYZ CAR PARKING BILL ********";
cout<<"\n\nBill Number: "<<billNo;
cout<<"\nCar Number: "<<carNo;
cout<<"\nParking Spot: "<<slotNo;
cout<<"\nEntry Time: "<<ctime(&entryTime);
cout<<"\nExit Time: "<<ctime(&exitTime);
cout<<"\nTotal Charges: Rs. "<<charges<<"/-";
cout<<"\nCurrent Status: PAID";
cout<<"\n\nEnter any key to go back to main menu..";
char c = getchar();
}
};
class ParkingLot
{
int capacity;
int totalFilled;
vector<bool> parkingSpaces;
vector<Vehicle> v;
public:
ParkingLot()
{
capacity = 100;
totalFilled = 0;
for(int i=0;i<capacity;++i)
parkingSpaces.push_back(false);
}
bool ifSlotAvailable()
{
if(totalFilled==capacity)
return false;
else
return true;
}
int getFreeSlot()
{
for(int i=0;i<capacity;++i)
{
if(parkingSpaces[i]==false)
{
parkingSpaces[i]=true;
totalFilled++;
return i+1;
}
}
return -1;
}
void newVehicle(Vehicle& x)
{
v.push_back(x);
}
void deleteVehicle(int slot)
{
parkingSpaces[slot-1] = false;
totalFilled--;
}
Vehicle findDepartingCar(int t) // t = ticket number
{
for(int i=0;i<v.size();++i)
{
int s = v[i].getTicketNo();
if(t == s)
return v[i];
}
return v[0];
}
int getCapacity()
{
return capacity;
}
int getTotalFilled()
{
return totalFilled;
}
void emptyParkingSpotsList()
{
for(int i=0;i<parkingSpaces.size();++i)
{
if(parkingSpaces[i]==false)
cout<<i+1<<", ";
}
}
void occupiedParkingSpotsList() // gives the list of occupied parking slots
{
for(int i=0;i<parkingSpaces.size();++i)
{
if(parkingSpaces[i]==true)
cout<<i+1<<", ";
}
}
};
void carArrival(ParkingLot& pl)
{
if(pl.ifSlotAvailable())
{
int slot = pl.getFreeSlot();
Vehicle obj;
obj.getTicket(slot);
pl.newVehicle(obj);
}
else
{
cout<<"Sorry no empty parking space available!";
}
}
void carDeparture(ParkingLot& pl)
{
int ticketno;
cout<<"Enter ticket number: ";
cin>>ticketno;
cin.ignore();
Vehicle curr = pl.findDepartingCar(ticketno);
pl.deleteVehicle(curr.getSlot());
system("cls");
curr.getBill();
}
void displayDetails(ParkingLot& pl)
{
cout<<"\n\n1. Get the total capacity of Parking Lot";
cout<<"\n2. Get total number of occupied parking spots";
cout<<"\n3. Get total number of empty parking spots";
cout<<"\n4. Get list of empty parking spots";
cout<<"\n5. Get list of occupied parking spots";
cout<<"\n6. Get the total number of parkings";
cout<<"\n7. Exit";
int choice;
do
{
cout<<"\nEnter your choice: ";
cin>>choice;
if(choice<1 || choice>7)
cout<<"\nInvalid Input";
else
break;
} while(true);
system("cls");
int c;
switch(choice)
{
case 1:
c = pl.getCapacity();
cout<<"\nThe capacity of parking lot is "<<c;
break;
case 2:
c = pl.getTotalFilled();
cout<<"\nThe number of occupied parking spots is "<<c;
break;
case 3:
c = pl.getCapacity()-pl.getTotalFilled();
cout<<"\nThe number of empty parking spots is "<<c;
break;
case 4:
cout<<"\nList of empty parking spots: ";
pl.emptyParkingSpotsList();
break;
case 5:
cout<<"\nList of occupied parking spots: ";
pl.occupiedParkingSpotsList();
break;
case 6:
cout<<"\nThe total number of parkings: "<<count;
break;
case 7:
break;
}
cin.ignore();
cout<<"\nEnter any key to return to main menu..";
char ch = getchar();
}
int main()
{
ParkingLot pl;
int choice;
do
{
system("cls");
cout<<"********* CAR PARKING MANAGEMENT SYSTEM *********";
cout<<"\n\n1. Arrival of a car";
cout<<"\n2. Departure of a car";
cout<<"\n3. Display details";
cout<<"\n4. Exit";
cout<<"\nSelect an option (1,2 or 3): ";
cin>>choice;
system("cls");
switch(choice)
{
case 1:
carArrival(pl);
break;
case 2:
carDeparture(pl);
break;
case 3:
displayDetails(pl);
break;
case 4:
exit(0);
default:
cout<<"Invalid Choice!";
break;
}
} while(true);
return 0;
}