-
Notifications
You must be signed in to change notification settings - Fork 7
/
problem34.cpp
79 lines (78 loc) · 1.18 KB
/
problem34.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
/*
Solved by Joel Felix
Dept of IT
*/
#include<iostream>
using namespace std;
class Vehicle
{
public:
virtual void park()=0;
};
class Motorbike : public Vehicle
{
static int mb_parking;
public:
void park()
{
mb_parking++;
}
static int mbParking()
{
return mb_parking;
}
};
int Motorbike::mb_parking=0;
class Car : public Vehicle
{
static int car_parking;
public:
virtual void park()
{
car_parking++;
}
static int carParking()
{
return car_parking;
}
};
int Car::car_parking=0;
class HandicappedCar : public Car
{
static int hcar_parking;
public:
void park()
{
hcar_parking++;
}
static int hcarParking()
{
return hcar_parking;
}
};
int HandicappedCar::hcar_parking=0;
main()
{
int v,p;
Vehicle *veh;
Motorbike mb;
Car c;
HandicappedCar hc;
cout<<"Enter the vehicle no:\n1.Motor Bike\n2.Car\n3.Handicapped Car\n";
cin>>v;
if(v==1)
veh=&mb;
else if(v==2)
veh=&c;
else
{
cout<<"Enter the parking area no:\n1.Car Parking Area\n2.Handicapped Car Parking Area\n";
cin>>p;
if(p==1)
veh=&c;
else
veh=&hc;
}
veh->park();
cout<<Motorbike::mbParking()<<"\t"<<Car::carParking()<<"\t"<<HandicappedCar::hcarParking()<<"\n";
}