A telephone company charges to cents per minutefor all calls outside the customers area code that last over 20 minutes .All other calls are 13 percents minute.Fields for each call include customer area code (three digits),customer phone number (seven digits),called area code (three digits),called number(seven digits)and called time in minutes(four digits).Display the customer area code,customer phone number,called area code,called number,called time in minutes and the total charge.Draw the flowchart for this program.
The correct answer and explanation is :
Problem Explanation and Solution
In this scenario, a telephone company charges 2 cents per minute for all calls that last over 20 minutes and are made outside the customer’s area code. For calls within the customer’s area code or calls that are 20 minutes or less, the charge is not applied.
Solution Breakdown
- Input Fields:
- Customer Area Code (3 digits)
- Customer Phone Number (7 digits)
- Called Area Code (3 digits)
- Called Number (7 digits)
- Called Time in Minutes (4 digits)
- Conditions to Apply Charge:
- The call lasts more than 20 minutes.
- The called area code does not match the customer’s area code.
- If both conditions are true, charge is calculated as:
- Charge = Called Time in Minutes × 0.02 (since it’s 2 cents per minute).
- Output Fields:
- Customer Area Code
- Customer Phone Number
- Called Area Code
- Called Number
- Called Time in Minutes
- Total Charge (if applicable)
Steps to Implement the Program:
- Step 1: Read the input values for each call: customer area code, customer phone number, called area code, called number, and called time in minutes.
- Step 2: Check if the call lasts more than 20 minutes and if the called area code differs from the customer’s area code.
- Step 3: If both conditions are met, calculate the total charge (called time × 0.02).
- Step 4: Display the customer’s and called party’s details along with the total charge (if applicable).
Example:
- Customer Area Code: 123
- Customer Phone Number: 5551234
- Called Area Code: 456
- Called Number: 5559876
- Called Time: 30 minutes
- Charge Calculation:
- Since the call is over 20 minutes and the area codes are different, charge = 30 * 0.02 = $0.60.
Flowchart
Here’s a basic description of the flowchart for this program:
- Start: Begin the program.
- Input Data: Get the values for customer area code, customer phone number, called area code, called number, and called time in minutes.
- Check Duration: Is the called time greater than 20 minutes?
- Yes: Proceed to the next step.
- No: Skip charge calculation.
- Check Area Code: Does the called area code match the customer’s area code?
- Yes: No charge.
- No: Proceed to charge calculation.
- Calculate Charge: Charge = called time * 0.02.
- Display Result: Show customer details, called details, and charge.
- End: Program finishes.
Explanation
This solution involves simple conditional statements to check whether the charge criteria are met. The flowchart guides the program logic, ensuring the steps for input, checks, and calculation are clearly defined. The charge is applied only when both conditions—call duration exceeding 20 minutes and a different area code—are satisfied. If these conditions aren’t met, no charge is computed, and the call information is displayed without additional charge details. This solution provides a clear structure for implementing the logic in a program.