- Write a return-value function named calcCharges() to calculate and return the parking charges for the customers. The company charges a RM1.00 minimum fee to park for up to one hour. An additional RM0.50 will be charged for each hour exceeding the first one hour. The maximum charge for any given 24-hour period is RM10.00. Assume that no car parks for longer than 24 hours at a time.
- Write a void function named calcTotal() to calculate the total charges for all the customers.
- Write the main program that allows the user to input number of customers and the hours parked for the customers. The program should use the function calcCharges()above to calculate the parking charges for each customer and function calcTotal() above to calculate the total charges for all the customers.
- Finally, your program should output the parking charges for each customer and the total charges for all the customers. Use the appropriate parameters to pass values in and out of functions.
#include <iostream>
#include <cmath>
using namespace std;
double calcCharges(int h){
double totalcharges;
if(h<=19.0){
totalcharges = (h - 1) * 0.5 + 1;
}else{
totalcharges = 10.0;
}
return totalcharges;
}
void calctotal(double sum, float all[], int size){
int x;
system ("CLS");
for( x = 0; x< size; x++){
if(all[x] != 0){
cout<<" Customer " <<x+1 <<" : RM" <<all[x] <<endl;
}
}
cout<< "Total charges for all the customers: "<<sum;
}
int main()
{
int hr, ch, size, c1, i = 0;
double total, sum;
float all[] = { 0.0 };
do{
cout<< " Select an action: \n";
cout<< " 1 : Add customer \n";
cout<< " 2 : View Total \n";
cin>>ch;
switch(ch) {
case 1:
cout<<"Enter the hours: \n";
cin>>hr;
total = calcCharges(hr);
all[i] = total;
i++;
cout<< " Total charges: RM" <<total;
cout<< "\n Enter 1 to continue, 2 to exit: \n";
cin>>c1;
ch = 0;
break;
case 2:
size = sizeof(all);
for(int i = 0; i < size; i++){
sum += all[i];
}
calctotal(sum, all, size);
break;
}
}
while (c1 == 1);
size = sizeof(all);
for(int i = 0; i < size; i++){
sum += all[i];
}
calctotal(sum, all, size);
}
Comments
Leave a comment