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

Your task is to write a C++ program that simulates a parking meter within the pa

ID: 646569 • Letter: Y

Question

Your task is to write a C++ program that simulates a parking meter within the parking deck. The program will start by reading in the time a car arrives in the parking deck. It will then ask you what time the car left the parking deck. You should then calculate the time that has passed between issuing the time ticket and the time the car left. Lastly, you will use this information to determine how much the person needs to pay upon leaving the deck. The rates are in the table below. Please read through all of the notes below!

You should write a single function for each of the following things:

Reading in the arrival times and departure times

Calculate the passage of time

Determine how much the driver needs to pay

Print out the receipt for the driver, including his arrival and departure times, time in the deck, and how much he owes.  

Time in Parking Deck

Rate in Dollars ($)

Less than 30 minutes

3.00

[30 Minutes 1 Hour)

5.00

[1 Hour 2 Hours )

10.00

[2 Hours 3 Hours )

15.00

[3 Hours 4 Hours )

30.00

Each half hour over four hours

30.00 + 5.00 per additional half hour

[12 Hours ? Hours )

Error prints out, see notes above.

Lost ticket

110.00

Special Parking Pass

5.00

Time in Parking Deck

Rate in Dollars ($)

Less than 30 minutes

3.00

[30 Minutes 1 Hour)

5.00

[1 Hour 2 Hours )

10.00

[2 Hours 3 Hours )

15.00

[3 Hours 4 Hours )

30.00

Each half hour over four hours

30.00 + 5.00 per additional half hour

[12 Hours ? Hours )

Error prints out, see notes above.

Lost ticket

110.00

Special Parking Pass

5.00

Explanation / Answer

#include<iostream>

using namespace std;

struct Time{
int hour;
int min;
};

void getTime(Time *arrivalTime, Time *departureTime){
char colon;
cout << "Enter the arrival time : (HH : MM) : ";
cin >> arrivalTime->hour;
cin >> colon;
cin >> arrivalTime->min;

cout << "Enter the departure time : (HH : MM) : ";
cin >> departureTime->hour;
cin >> colon;
cin >> departureTime->min;
}

int calculatePassageOfTime(Time arrivalTime, Time departureTime){
int totalArrivalTime, totalDepartureTime;

totalArrivalTime = arrivalTime.hour*60 + arrivalTime.min;
totalDepartureTime = departureTime.hour*60 + departureTime.min;

int diff = totalDepartureTime - totalArrivalTime;

return diff;
}

double calculateBillAmount(int timeDiff){
double rate;
if(timeDiff <= 30){
rate = 3.00;
}else if(timeDiff > 30 && timeDiff <= 60){
rate = 5.00;
}else if(timeDiff > 60 && timeDiff <= 120){
rate = 10.00;
}else if(timeDiff > 120 && timeDiff <= 1800){
rate = 15.00;
}else if(timeDiff > 180 && timeDiff <= 240){
rate = 30.00;
}else if(timeDiff > 240 && timeDiff <= 720){
rate = 30.00 + ((timeDiff - 240)/30)*5.00;
}else{
cout << "Error ";
return -1;
}
return rate;
}

void printReceipt(Time arrivalTime, Time departureTime, int timeDiff, double rate){
cout << "Arrival Time : " << arrivalTime.hour << ":" << arrivalTime.min << endl;
cout << "Departure Time : " << departureTime.hour << ":" << departureTime.min << endl;
cout << "Time in the deck : " << timeDiff/60 << " hours and " << timeDiff%60 << " secs " << endl;
cout << "Bill Amount : " << rate << endl;
}

int main(){
Time arrivalTime,departureTime;
int timeDiff;
double billAmount;

getTime(&arrivalTime, &departureTime);
timeDiff = calculatePassageOfTime(arrivalTime, departureTime);
billAmount = calculateBillAmount(timeDiff);
printReceipt(arrivalTime, departureTime, timeDiff, billAmount);
}