In: Computer Science
use c++
Parking charge application: A parking garage charges a $20.00 minimum fee to park for up to 3 hours. The garage charges an additional $5.00 per hour for hour or part thereof in excess of 3 hours. The maximum charge for any given 24-hour period is $50.00. Assume that no car parks for longer than 24 hours at a time. Write a program that calculates and prints the parking charge for each of 3 customers who parked their cars in this garage yesterday. You should enter the hours parked for each customer. Your program should save the result in a array of Customer. The class customer is the following:
class customer{ string plate; float hour; float fee; }
Your program should use the function calculateCharges to determine the fee for each customer. You should print the result for the 3 customers in the following format:
Plate Hours Charge
132AAC 1.5 20.00
236URT 4.0 25.00
390ROP 24.0 50.00
TOTAL 29.5 95.00
In doing this question make sure to keep the array of customer as global variable.
#include <bits/stdc++.h>
using std::cout;
class Customer{
public:
std::string plate;
float hour;
float fee;
float calculateCharges(){
if (hour > 3.0)
fee = 20.0 + (hour - 3) * 5.0;
else fee = 20.0;
if (fee > 50.0)
fee = 50.0;
else
;
return fee;
}
};
Customer c[3];
int main(){
int totalHrs= 0;
int totalFee =0;
c[0].plate = "132AAC";
c[0].hour = 1.5;
c[1].plate = "236URT";
c[1].hour = 4.0;
c[2].plate = "390ROP";
c[2].hour = 24.0;
cout << "Plate" << "\t" << "Hours" << "\t" << "Charge" << std::endl;
for(int i = 0; i < 3; i++){
totalHrs += c[i].hour;
totalFee += c[i].calculateCharges();
cout << c[i].plate << "\t" << c[i].hour << "\t" << c[i].fee << std::endl;
}
cout << "Total" << "\t" << totalHrs << "\t" << totalFee << std::endl;
return 0;
}