-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathparking.cpp
53 lines (47 loc) · 1.08 KB
/
parking.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
#include<iostream>
#include<ctime>
#include"parking.h"
using std::cout;
using std::endl;
bool Parking::isFull() const
{
if (occupiedPlaces == MAX_CAR)
return true;
return false;
}
void Parking::enterPar(Car& car, int currentTime)
{
srand(time(0));
int p = (int)(rand() % MAX_CAR + 1);
while (parking[p].getPlace() != -1)
p = (int)(rand() % MAX_CAR + 1);
occupiedPlaces++;
car.enter(p, currentTime);
parking[p] = car;
extern QLabel *l1,*l2;
l1->setText(QString::number(occupiedPlaces));
l2->setText(QString::number(MAX_CAR-occupiedPlaces));
}
void Parking::remove(int place)
{
parking[place].reset();
occupiedPlaces--;
extern QLabel *l1,*l2;
l1->setText(QString::number(occupiedPlaces));
l2->setText(QString::number(MAX_CAR-occupiedPlaces));
}
bool Parking::findCar(const string& id, bool print) const
{
extern QString state;
for (int i = 1; i <= MAX_CAR; i++)
{
if (id == parking[i].getNumber())
{
int place = parking[i].getPlace();
if (print)
state=QString::number(place);
return true;
}
}
return false;
}