Problem 1 (30 points): Write a C program that calculates the water bill accordin
ID: 3882611 • Letter: P
Question
Problem 1 (30 points): Write a C program that calculates the water bill according to the chart below. The program should let a user enter the user type and the water usage amount and then displays the total cost (including tax). See sample code execution. Fixed cost Residential- fixed cost 9.00 14.00 Business- fized cost Water Usage ( in cubic feet Cost (S) per cubic feet for the first 700 cf, ws 700 for the next 800 cf 700 w 1 500 for additional cf above 1500 w 1500 0.018 0.032 0.03 Residential The tax rate is 6.1% Red is entered by a user Sample Code Execution #1 Enter User Type (R for Residential B for Business): E - Enter water usag in cubic feet: 58 Wrong User Type Not valid user type, Your code should display the message Sample Code Execution #2 Enter User Type R for Residential, B for Business): R Enter water usage in cubic feet: 53.5Explanation / Answer
#include <iostream>
using namespace std;
double taxRate = 0.061; // Tax rate is 6.1% means 0.061
double CalculateResidentialCost(double waterUsage )
{
double Cost = 0.0;
double TotalTax = 0.0;
if(waterUsage <= 700)
{
Cost = waterUsage * 0.018;
}
else if( waterUsage > 700 && waterUsage <=1500)
{
Cost = waterUsage * 0.032;
}
else if(waterUsage > 1500)
{
Cost = waterUsage * 0.08;
}
// Calculate Total tax
TotalTax = Cost * taxRate;
// Total Amount
Cost = Cost + TotalTax;
return Cost;
}
double CalculateBussinessCost(double waterUsage )
{
double Cost = 0.0;
double TotalTax = 0.0;
Cost = waterUsage * 0.0288;
// Calculate Total tax
TotalTax = Cost * taxRate;
// Total Amount
Cost = Cost + TotalTax;
return Cost;
}
void doOperation(char usrType, double waterUsage )
{
double cost = 0.0;
if(usrType == 'R' || usrType == 'r')
{
cost = CalculateResidentialCost(waterUsage);
}
else if(usrType == 'B' || usrType == 'b')
{
cost = CalculateBussinessCost(waterUsage);
}
else
{
cout<< " Wrong User Type "<<endl;
return;
}
cout<<" Total cost is " << cost <<endl;
}
void AcceptInput()
{
char usrType;
double waterUsage;
cout<<" Enter User Type ( R for Residential, B for Bussiness): ";
cin>>usrType;
cout<<" Enter water usage in cubic feet: ";
cin>>waterUsage;
doOperation(usrType, waterUsage);
}
int main()
{
AcceptInput();
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.