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
|
#include <iostream>
#include <string>
using namespace std;
class Vehicle
{
public:
string RN;
string manufacturer;
string model;
Vehicle()
{
RN="";
manufacturer="";
model="";
}
void setVehicle(string a,string b, string c)
{
RN=a;
manufacturer=b;
model=c;
}
virtual void display();
};
class ParkingLot
{
public:
ParkingLot( int size)
{
numof_slots=size;
}
// returns true if parking slot was available, false otherwise
bool park(Vehicle*)
{
int count = 0;
for (int i = 0; i < numof_slots; i++)
{
if (parkedVehicles[i] == 0)
{count++;
return true;}
else
{return false;}
}
if (count > 0)
{
return true;
}
}
Vehicle **getParkedVehicles()
{
return parkedVehicles;
}
int getNum_of_slots()
{return numof_slots;}
private:
int numof_slots;
Vehicle** parkedVehicles;
};
class Car:public Vehicle
{
private:
int NOD;
public:
Car():Vehicle()
{NOD=0;
}
Car(string a,string b,string c,int d)
{
setVehicle(a,b,c);
NOD=d;
}
virtual void::display()
{
cout<<"Bike :"<<endl;
cout<<"Registeration number = "<<RN<<endl;
cout<<"Manufacturer = "<<manufacturer<<endl;
cout<<"model = "<<model<<endl;
cout<<"Number of doors = "<<NOD<<endl;
}
};
class Bike:public Vehicle
{
private:
public:
Bike():Vehicle()
{
}
Bike(string a,string b,string c)
{
setBike(a,b,c);
}
void setBike(string a, string b, string c)
{
setVehicle(a,b,c);
}
virtual void::display()
{
cout<<"Bike :"<<endl;
cout<<"Registeration number = "<<RN<<endl;
cout<<"Manufacturer = "<<manufacturer<<endl;
cout<<"model = "<<model<<endl;
}
};
int main()
{
ParkingLot *fastParking= new ParkingLot(30);
Car *corolla1= new Car("LOX 213", "Toyota", "Corolla", 4);
Bike* honda1= new Bike("LED 2179", "Honda", "CD70");
fastParking->park(corolla1);
fastParking->park(honda1);
int num=fastParking->getNum_of_slots();
Vehicle ** vehicles= fastParking->getParkedVehicles();
for(int i=0; i<num; i++)
{
/*the display() method displays registration number, manufacturer and
model in case of bike and in case of car it displays all of above as well
as number of doors*/
if(vehicles[i]!=0)
{
cout<<"Parking slot "<<i+1<< " has ";
vehicles[i]->display();
}
else
cout<<"Parking slot "<<i+1<< " is empty"<<endl;
}
return 0;
}
| |