Question: Making a parking lot C++ program You will write a .cpp file that will simulate a parking lot. The focus is writing the following functions
Making a parking lot C++ program
You will write a .cpp file that will simulate a parking lot. The focus is writing the following functions that will work as described. Your main function will be used simply to test your functions. Your parking lot will be a one dimensional array of strings that will store a vehicle's license plate number if the "spot" is occupied.
bool isEmptySpace( string lot [], int x ) - This function will return true if the spot at index x is vacant. You can assume that x is a valid index in range: 0 <= index < lot size.
bool isFull( string lot [], int size ) - This function will return true if there are no vacancies (all spots are occupied), false if there is at least one spot that is vacant.
void printStats( string lot [], int size ) - This function will print out the status of each spot in the parking lot. If the spot is occupied, it will print out the license plate number of the car that is occupying the spot, otherwise, it will print "Empty" or "Vacant".
bool park( string lot [], int size, string license ) - This function will attempt to park a car in any spot in the parking lot. You can choose which algorithm to use to determine the spot, but the car cannot be placed in a spot that is already occupied. This function will return false if the car could not be parked because the lot is full. It will return true if the license number is saved to the array.
bool park( string lot[], int size, string license, int x ) - This function attempts to park a car in a specific parking spot x. The car cannot be placed in the spot if it is already occupied. This function will return false if the car cannot be parked. It will return true if the car is parked at spot x and the license number is saved to the array.
Here is a sample main that you can use to test your functions (please note that all your functions should work for any size parking lot):
int main() { const int SIZE = 5; string cars[ SIZE ]; park( cars, SIZE, "1ABC234" ); park( cars, SIZE, "9XYZ876", 2 ); park( cars, SIZE, "5D12345" ); if( !isFull( cars, SIZE ) ) printStats( cars, SIZE ); if( !isEmpty( cars, 2 ) ) cout << "Occupied" << endl;
if( !park( cars, SIZE, "TEST123", 2 ) cout << "You did not park on top of another car." << endl;
system( "pause" ); return 0; }
Example output: 0: Empty 1: 1ABC234 2: Empty 3: Empty
Any help with this is much appreciated. Thank you!
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
