Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Making a parking lot C++ program You will write a .cpp file that will simulate a

ID: 3695773 • Letter: M

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 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".
Example output:
0: Empty
1: 1ABC234
2: Empty
3: Empty

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;
}

Explanation / Answer

//This program calculates charges for a parking garage based on the type of
//vehicle and the time spent in the garage.
//Author: Tonia Clark November 2011.
#include <iostream>
using namespace std;

//constants for rates
#define firstCarRate 0.00 //first rate for cars.
#define secondCarRate 1.25 //second rate for cars.
#define firstTruckRate 3.75 //first rate for trucks.
#define secondTruckRate 4.50 //second rate for trucks.
#define firstBusRate 2.00 //first rate for buses.
#define secondBusRate 2.50 //second rate for buses.

//getInfo Function Prototype.
void getInfo(char *vehicle, int *hourIn, int *minIn, int *hourOut, int *minOut);

//time function prototype.
void time(int hourIn, int minIn, int hourOut, int minOut, int *houtParkTime, int * minParkTime, int *roundedTotal, int *round);

//rate function prototype.
void rate(char vehicle, int *units, float *firstRate, float *secondRate);

//charge function prototype.
void charge(int roundedTotal, int units, float firstRate, float secondRate, float *totalCharge);

//print bill function prototype.
void printBill (char vehicle, int hourIn, int minIn, int hourOut, int minOut, int hourParkTime, int minParkTime, int roundedTotal, float totalCharge);

//global variables
char vehicle;
int units;
int hourIn;
int minIn;
int hourOut;
int minOut;
int hourParkTime;
int minParkTime;
int roundedTotal;
int round;
float firstRate;
float secondRate;
float totalCharge;

int main(void)
{
getInfo(&vehicle, &hourIn, &minIn, &hourOut, &minOut);
time(hourIn, minIn, hourOut, minOut, &hourParkTime, &minParkTime, &roundedTotal, &round);
rate(vehicle, &units, &firstRate, &secondRate);
charge(roundedTotal, units, firstRate, secondRate, &totalCharge);
printBill(vehicle, hourIn, minIn, hourOut, minOut, hourParkTime, minParkTime, roundedTotal, totalCharge);
return 0;
}//end of main.

//function definition for get info.
void getInfo(char *vehicle, int *hourIn, int minIn, int *hourOut, int *minOut)
{
cout << " Type of vehicle? ";
cout << " (enter C for car,T for truck or B for bus).";
cin >> vehicle;
//check for valid vehicle type
{
switch(*vehicle)
{
{
case 'C': cout << "You entered C. ";
case 'c': cout << "You entered c. ";
break;
case 'T': cout << "You entered T. ";
case 't': cout << "You entered t. ";
break;
case 'B': cout << "You entered B. ";
case 'b': cout << "You entered b. ";
break;
default: cout << "You did not enter a valid vehicle type ";
cout << "Please Enter C,c,T,t,B, or b ";

return;
}

//get the hour that the vehicle entered the garage.
cout << " Hour vehicle entered garage? ";
cin >> *hourIn;
//validate input for hourIn
if(*hourIn < 0 || *hourIn < 23)
{
cout << "invalid input. enter an integer between 0 and 23.";

}

//get the minute that the vehicle entered the garage.
cout << " Minute vehicle entered garage? ";
cin >> minIn;
//validate input for minIn.
if(minIn < 0 || minIn > 60)
{
cout << "invalid input. enter a number between 0 and 60.";
}

//get the hour vehicle exits garage.
cout <<" Hour vehicle exits garage? ";
cin >> *hourOut;
//validate input for hourOut.
if(*hourOut < 0 || *hourOut < 23)
{
cout << "invalid input. enter an integer between 0 and 23.";
}

//get the minute vehicle exits garage.
cout << " Minute vehicle exits garage?";
cin >> *minOut;
//validate input for minOut.
if(minOut < 0 || *minOut > 60)
{
cout << "invalid input. enter a number between 0 and 60.";

return;
}
}
//function definition for time.
void time(int hourIn, int minIn, int hourOut, int minOut, int *hourParkTime, int *minParkime, int *roundedTotal, int *rounded)
{
if (*minOut < minIn)
{
minOut = minOut + 60;
hourOut = hourOut - 1;
}
else
{
hourParkTime = hourOut - hourIn;
minParkTime = *minOut - minIn;
}
if(minParkTime >= 1)
{
round = hourParkTime + 1;
}
else
{
round = hourParkTime;
}
roundedTotal = round;
return;
}
//Function definition for rate.
void rate(char vehicle, int *units, float *firstRate, float *secondRate)
{
switch(*vehicle)
{
{
case 'c':
case 'C': units = 3;
firstRate = firstCarRate;
break;
}
{
case 't':
case 'T': units = 1;
firstRate = firstTruckRate;
secondRate = secondTruckRate;
break;
}
case 'b':
case 'B': units = 2;
firstRate = firstBusRate;
secondRate = secondBusRate;
break;

{
default:
cout << " Enter a valid vehicle type.";

return;
}
//Function definition for charge.
void charge(int roundedTotal, int units, float firtsRate, float secondRate, float totalCharges)
if(roundedTotal <= units)
{
totalCharge = (roundedTotal * firstRate);
}
else
{
totalCharge = (roundedTotal - units) * (secondRate) + (units * firstRate);

return;
}

//Function definition for print Bill.
void printBill(char vehicle, int hourIn, int minIn, int hourOut, int minOut, int hourParkTime, int minParkTime, int roundedTotal, float totalCharge)
{
cout << "Vehicle Type:/t/t"<< vehicle <<endl;
cout << "Time In:/t/t" <<hourIn<<":"<<minIn <<endl;
cout << "Time Out:/t/t" <<hourOut<<":"<<minOut <<endl;
cout << "Total Park Time:/t/t" <<roundedTotal <<endl;
cout << "Total Charge:/t/t" <<totalCharge<<endl;
return;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote