Print Friendly and PDF
(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:
(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:

Solution:
 #include < iostream>
#include < iomanip>
 
using namespace std;
 
double calculateCharges( double );
 
int main()
{
  double first, second, third;
 
  cout << "Enter hours for three customers: ";
  cin >> first >> second >> third;
  cout << "Car\tHours\tCharge\n";
  cout << "1\t" << fixed << setprecision( 1 ) << first
       << setprecision( 2 ) << "\t" << calculateCharges( first ) << endl;
  cout << "2\t" << fixed << setprecision( 1 ) << second
       << setprecision( 2 ) << "\t" << calculateCharges( second ) << endl;
  cout << "3\t" << fixed << setprecision( 1 ) << third
       << setprecision( 2 ) << "\t" << calculateCharges( third ) << endl;   
  cout << "TOTAL\t" << fixed << setprecision( 1 ) << first + second + third
       << fixed << setprecision( 2 ) << "\t" 
        << calculateCharges( first ) + calculateCharges( second ) + calculateCharges( third ) << endl;
 
   //for pause
   system("PAUSE");
   return 0;
}
 
//function charge calculation
double calculateCharges( double hours )
{
  if( hours < 3 )
    return 2.00;
  else
    {
        if ( hours < 24 )
          return 2.00 + ( hours - 3 ) * 0.5;
        else
          return 10.00;
      }
}
 
 
zubairsaif

Zubair saif

A passionate writer who loves to write on new technology and programming

Post A Comment:

0 comments: