In: Computer Science
In this exercise, you will create a program that displays the amount of a cable bill. The amount is based on the type of customer shown in figure 10-30. For a residential customer, the user will need to enter the number of premium channels only. For a business customer, the user will need to enter the number of connections and the number of premium channels. Use a separate void function for each customer type. Enter your C++ instructions into the source file and any appropriate comments and any additional instructions required by the compiler. Test the program appropriately.
FIG10-3
Residential Customers:
Processing Fee: $4.50
Basic Service Fee: $30
Premium Channels: $5 per channel
Business Customers:
Processing Fee: $16.50
Basic Service Fee: $80 for the first 5 connections, $4 for each additional connection
Premium channels: $50 per channel regardless of the number of connections
#include <iostream>
using namespace std;
void residentialCustomer(double &chargeResidential)
{
int numChannels;
cout<<"\nEnter the number of premium channels
only : ";
cin>>numChannels;
chargeResidential = 4.5 + 30.0+ 5*numChannels;
}
void businessCustomer(double &chargeBusiness)
{
int numChannels,numConnections;
cout<<"\nEnter the number of premium channels :
";
cin>>numChannels;
cout<<"\nEnter the number of connections :
";
cin>>numConnections;
if(numConnections <= 5)
chargeBusiness = 16.50 + 80*numConnections+
50*numChannels;
else
chargeBusiness = 16.50 + 84*numConnections+
50*numChannels;
}
int main() {
char customerType;
double avgChargeResidential = 0;
double avgChargeBusiness = 0;
double chargeResidential = 0;
double chargeBusiness = 0;
int countR = 0;
int countB = 0;
do
{
cout<<"\nEnter the type of customer < R-
Residential customer> or < B - Business Customer> < Z -
exit>: ";
cin>>customerType;
if(customerType == 'X')
break;
switch(customerType)
{
case 'R' :
residentialCustomer(chargeResidential);
cout<<"\nCharges for
residential customer : "<<chargeResidential;
avgChargeResidential +=
chargeResidential;
countR++;
break;
case 'B' :
businessCustomer(chargeBusiness);
cout<<"\nCharges for
business customer : "<<chargeBusiness;
avgChargeBusiness +=
chargeBusiness;
countB++;
break;
default : cout<<"\nInvalid
customer type ";
break;
}
}while(customerType != 'X');
cout<<"\nAverage charge for residential
customers : "<<avgChargeResidential/countR;
cout<<"\nAverage charge for business customers :
"<<avgChargeBusiness/countB;
return 0;
}
Output:
Enter the type of customer < R- Residential customer> or < B - Business Customer> < Z - exit>: R Enter the number of premium channels only : 100 Charges for residential customer : 534.5 Enter the type of customer < R- Residential customer> or < B - Business Customer> < Z - exit>: B Enter the number of premium channels : 122 Enter the number of connections : 6 Charges for business customer : 6620.5 Enter the type of customer < R- Residential customer> or < B - Business Customer> < Z - exit>: R Enter the number of premium channels only : 150 Charges for residential customer : 784.5 Enter the type of customer < R- Residential customer> or < B - Business Customer> < Z - exit>: B Enter the number of premium channels : 150 Enter the number of connections : 3 Charges for business customer : 7756.5 Enter the type of customer < R- Residential customer> or < B - Business Customer> < Z - exit>: X Average charge for residential customers : 659.5 Average charge for business customers : 7188.5
Do ask if any doubt. Please upvote.