(Parking Charges) 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 at a time. Write a program that calculates and prints the parking charges for each of three customers who parked their cars in this garage yesterday. You should enter the hours parked for each customer. Your program should print the results in a neat tabular format and should calculate and print the total of yesterday’s receipts. The program should use the function calculateCharges to determine the charge for each customer. Your outputs should appear in the following format:
What will be an ideal response?
```
// Calculate charges for 3 cars at parking garage.
#include
#include
#include
using namespace std;
double calculateCharges( double ); // function prototype
int main()
{
double hour; // number of hours for current car
double currentCharge; // parking charge for current car
double totalCharges = 0.0; // total charges
double totalHours = 0.0; // total number of hours
bool first = true; // used for printing table headers
cout << fixed; // set floating-point number format
cout << "Enter the hours parked for 3 cars: ";
// loop 3 times for 3 cars
for ( int i = 1; i <= 3; i++ )
{
cin >> hour;
totalHours += hour; // add current hours to total hours
// if first time through loop, display headers
if ( first )
{
cout << setw( 5 ) << "Car" << setw( 15 ) << "Hours"
<< setw( 15 ) << "Charge\n";
first = false; // prevent from printing again
} // end if
// calculate current car's parking charge
currentCharge = calculateCharges( hour );
totalCharges += currentCharge; // update total charges
// display row data for current car
cout << setw( 3 ) << i << setw( 17 ) << setprecision( 1 ) << hour
<< setw( 14 ) << setprecision( 2 ) << currentCharge << "\n";
} // end for
// display row data for totals
cout << setw( 7 ) << "TOTAL" << setw( 13 ) << setprecision( 1 )
<< totalHours << setw( 14 ) << setprecision( 2 )
<< totalCharges << endl;
} // end main
// calculateCharges returns charge according to number of hours
double calculateCharges( double hours )
{
double charge; // calculated charge
if ( hours < 3.0 ) // $2 for up to 3 hours
charge = 2.0;
else // $.50 for each extra hour
charge = 2.0 + .5 * ceil( hours - 3.0 );
// return charge, ensuring charge is not over $10.00
return ( charge > 10.0 ? 10.0 : charge );
} // end function calculateCharges
```
You might also like to view...
Which of the following buttons should you click to start the presentation with the current slide?
A.
B.
C.
D.
What is the most common use of coaxial cable in networking today?
A. connecting computers in a small network B. connecting two computers in a point-to-point connection C. connecting a cable modem to an Internet Service Provider (ISP) D. in a multipoint connection
The isNaN() function returns a value of true if a string input is a number
Indicate whether the statement is true or false
Viewers just need a free ____________________ to be able to experience your presentation online as you give it-just as if you were in the same room.
Fill in the blank(s) with the appropriate word(s).