A parking garage charges a $2.00 minimum fee to park for up to three hours. The
ID: 3903359 • Letter: A
Question
A parking garage charges a $2.00 minimum fee to park for up to three hours. The garage charges an additional $0.50 per hour for each hour, or part thereof, in excess of three hours. The maximum charge for any given 24-hour period is $10.00. Assume that no car parks for longer than 24 hours.
Write a program that calculates and displays the parking charges for each customer who parked in the garage on a given day and displays the running total of that day’s receipts.
Specification
Create a ParkingCharges class
create parkingcharges constructor that takes data members and intializes them
Create a member function double parkingCharges(double hours).
Accepts the hours parked as an argument.
Calculates the parking charge based on the hours.
Returns the parking charge.
Add other data members and member functions as appropriate.
Separate the class into both interface (.h) and implementation (.cpp) files.
Write an application the uses the ParkingCharges class and does the following:
Enter the hours parked.
Calculate and display the charges for this customer.
Add charges to the running total and display the running total.
Continue as long as there is another customer.
Test! Test! Test!
Complete this in C++***
Explanation / Answer
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <string>
using namespace std;
const int CARS = 3;
static int hours[CARS] = {0, 0, 0,};
void enterHoursParked()
{
for(int i=0;i<CARS;i++)
{
cout << "Enter the hours parked for each car"<< i;
cin >> hours[i];
}
}
float calculateCharges(int ilen)
{
float finalCharge;
if (ilen <= 3)
finalCharge = 2;
if (ilen >= 19)
finalCharge = 10;
if (ilen > 3)
finalCharge = 2 + (float)(ilen - 3) * .50;
return finalCharge;
}
void printCharges(int carno, int hours, float finalCharge)
{
if(carno == 0)
cout << "Car Hours Chargen";
else
cout << (carno)<<" "<< hours<<" "<< finalCharge<<"n";
}
int main()
{
cout << "Welcome!" << endl;
enterHoursParked();
for (int i = 0; i <= CARS; i++)
{
float finalCharge = calculateCharges(hours[i]);
printCharges(i,hours[i],finalCharge );
}
int l;
cin>>l;
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.