Tutorial#22 - Programming Example-3 (Cable Company Billing) | Control Structures | Part-1

Programming Example-3 (Cable Company Billing)

Cable Company Billing Example: 

This programming example demonstrates a program that calculates a customer’s bill for a local cable company. There are two types of customers: residential and business. There are two rates for calculating a cable bill: one for residential customers and one for business customers. 
For residential customers, the following rates apply:
Bill processing fee: $4.50
Basic service fee: $20.50
Premium channels: $7.50 per channel

For business customers, the following rates apply:
Bill processing fee: $15.00
Basic service fee: $75.00 for first 10 connections, $5.00 for each additional connection
Premium channels: $50.00 per channel for any number of connections

The program should ask the user for an account number (an integer) and a customer code. Assume that R or r stands for a residential customer, and B or b stands for a business customer.

Input: The customer’s account number, customer code, number of premium channels to which the user subscribes, and, in the case of business customers, number of basic service connections.

Output: Customer’s account number and the billing amount.

PROBLEM ANALYSIS AND ALGORITHM DESIGN:
The purpose of this program is to calculate and print the billing amount. To calculate the billing amount, you need to know the customer for whom the billing amount is calculated (whether the customer is residential or business) and the number of premium channels to which the customer subscribes. In the case of a business customer, you also need to know the number of basic service connections and the number of premium channels. Other data needed to calculate the bill, such as the bill processing fees and the cost of a premium channel, are known quantities. The program should print the billing amount to two decimal places, which is standard for monetary amounts. This problem analysis translates into the following algorithm:
1. Set the precision to two decimal places.
2. Prompt the user for the account number and customer type.
3. Based on the customer type, determine the number of premium channels and basic service    connections, compute the bill, and print the bill:
   a. If the customer type is r or R,
i. Prompt the user for the number of premium channels.
ii. Compute the bill.
iii. Print the bill.
   b. If the customer type is b or B,
i. Prompt the user for the number of basic service connections and the number of    premium channels.
ii. Compute the bill.
iii. Print the bill.

MAIN ALGORITHM:
Based on the preceding discussion, you can now write the main algorithm.
1. To output floating-point numbers in a fixed decimal format with a decimal point and trailing zeros, set the manipulators fixed and showpoint. Also, to output floating-point numbers with two decimal places, set the precision to two decimal places. Recall that to use these manipulators, the program must include the header file iomanip.
2. Prompt the user to enter the account number.
3. Get the customer account number.
4. Prompt the user to enter the customer code.
5. Get the customer code.
6. If the customer code is r or R,
a. Prompt the user to enter the number of premium channels.
b. Get the number of premium channels.
c. Calculate the billing amount.
d. Print the account number and the billing amount.
7. If the customer code is b or B,
a. Prompt the user to enter the number of basic service connections.
b. Get the number of basic service connections.
c. Prompt the user to enter the number of premium channels.
d. Get the number of premium channels.
e. Calculate the billing amount.
f. Print the account number and the billing amount.
8. If the customer code is something other than r, R, b, or B, output an error message.
For Steps 6 and 7, the program uses a switch statement to calculate the bill for the

Comments