In this lab, you are going to use the concept of inheritance to simulate the events happening in a parking lot. Specifically, you need to model the relationship between different types of car as well as the relationship between the cars and the parking lot. The source files are available HERE.
In order to manage the parking lot more clearly by documenting the entering and leaving information, you are required to construct a parking lot management system.
For simplicity, we assume that the parking lot has only 2 parking spots, and each vehicle will only
occupy 1 parking spot. The fee only depends on the types of vehicle and the fee rate of the parking lot.
The parking time is ignored in this lab.
There are 5 classes involved: ParkingLot
, Vehicle
, Bus
, Truck
,
and PrivateCar
.
The relationships between them are shown in the following figures. Detailed descriptions for each class can also be found below.
Note: '+': public; '-': private; '#': protected
assign_space
checks whether there is still a space for the new vehicle and assign the space for the vehicle.
It will take a pointer of Vehicle as input and return a bool value to indicate the status.
If there is a space, output plate_no enter the parking lot and get a parking spot.
and return true
, otherwise output Failed to assign space for plate_no.
and return false.
The function reclaim_space
reclaims spaces, calculates and charges the fee from the vehicles according to their types, and add it to the income of the parking lot. The types are listed in a enumeration, namely, DEFAULT, PRIVATE_CAR, BUS, TRUCK
, which are given.
Bus, Truck, and PrivateCar objects will call this function with their corresponding type
and the fee they should paid is calculated as type*fee_rate
.
If succeed in reclaiming a space, the function output plate_no leave the parking lot and pay fee for the space
and return the fee, otherwise it output There is no a vehicle with the plate No. of plate_no.
and return -1 to indicate the failure.
The function print
shows the information of the parking lot, including the parking vehicles and the total income.
enter
triggers the assign_space
function of the parking lot and changes the status of itself to true
.
The function leave
triggers the reclaim_space
function of the parking lot, calculates the fee, add it to the total fee, and changes the status of itself to false
. Remember to check the status of the vehicle before triggering the reclaim_space
function.
The function print
shows the information of the vehicle, including the plate number and the total fee paid for parking.
Vehicle
class.
This class contains the number of passengers.
The constructor takes in a string and an int as the plate number and the number of passengers respectively.
It has 2 member functions: leave
and print
.
The leave
function triggers the reclaim_space
function of the parking lot, calculates the fee, add it to the total fee, and changes the status of the bus to false
. Remember to check the status of the vehicle before triggering the reclaim_space
function. If the vehicle is not parking, output plate_no is not parking so it cannot leave!
.
The print
function prints the plate number, the number of passengers, and the total fee paid for parking.
Vehicle
class.
This class contains capacity.
The constructor takes in a string and an int as the plate number and the capacity respectively.
It has 2 member functions: leave
and print
.
The leave
triggers the reclaim_space
function of the parking lot, calculates the fee, add it to the total fee, and changes the status of the truck to false
. Remember to check the status of the vehicle before triggering the reclaim_space
function. If the vehicle is not parking, output plate_no is not parking so it cannot leave!
.
The print
function prints the plate number, the capacity, and the total fee paid for parking.
Vehicle
class.
This class contains brand.
The constructor takes in 2 strings as the plate number and the brand respectively.
It has 2 member functions: leave
and print
.
The leave
triggers the reclaim_space
function of the parking lot, calculates the fee, add it to the total fee, and changes the status of the private car to false
. Remember to check the status of the vehicle before triggering the reclaim_space
function. If the vehicle is not parking, output plate_no is not parking so it cannot leave!
.
The print
function prints the plate number, the brand, and the total fee paid for parking.
ParkingLot.h/.cpp
, Truck.cpp/.h
, Bus.cpp/.h
and PrivateCar.cpp/.h
ParkingLot
is given to you in ParkingLot.h
and the constructor, destructor and assign_space
member function has already been implemeted in ParkingLot.cpp
. You will need to implement the other member functions.Vehicle
is given to you in Vehicle.h and Vehicle.cpp
for your reference.PrivateCar, Bus and Truck
.Currently 0 vehicles in this parking lot, the total income is 0. The private car is AS134 with the brand of M-Benz. It has paid totally 0. AS134 enter the parking lot and get a parking spot. Currently 1 vehicles in this parking lot: AS134, the total income is 0. AS134 has been parking so it cannot leave! Currently 1 vehicles in this parking lot: AS134, the total income is 0. AS134 leave the parking lot and pay 2.4 for the space. Currently 0 vehicles in this parking lot, the total income is 2.4. The private car is AS134 with the brand of M-Benz. It has paid totally 2.4. The truck is XY778 with the capacity of 15. It has paid totally 0. The bus is QW907 with 12 passengers. It has paid totally 0. XY778 is not parking so it cannot leave! XY778 enter the parking lot and get a parking spot. QW907 enter the parking lot and get a parking spot. Currently 2 vehicles in this parking lot: XY778, QW907, the total income is 2.4. Failed to assign space for CY890. QW907 leave the parking lot and pay 4.8 for the space. XY778 leave the parking lot and pay 7.2 for the space. The bus is QW907 with 12 passengers. It has paid totally 4.8. The truck is XY778 with the capacity of 15. It has paid totally 7.2. Currently 0 vehicles in this parking lot, the total income is 14.4.
- Bus.h - Bus.cpp - ParkingLot.h - ParkingLot.cpp - PrivateCar.h - PrivateCar.cpp - Truck.h - Truck.cppYou can submit your codes multiple times to ZINC before the deadline. Only the last submission will be graded.