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 :
To solve the problem, let’s break it down step by step:
Problem Understanding:
The telephone company charges a fee for calls made outside the customer’s area code if the call lasts for more than 20 minutes. The total charge is computed by multiplying the time (in minutes) with the rate per minute for calls outside the area code. All other calls (either within the area code or lasting 20 minutes or less) are charged a different, presumably lower rate (e.g., 13 cents per minute). We are tasked to compute the total charge for each call and display the details of the call, including the customer and called information.
Fields for Each Call:
- Customer Area Code (3 digits)
- Customer Phone Number (7 digits)
- Called Area Code (3 digits)
- Called Phone Number (7 digits)
- Called Time (in minutes, 4 digits)
Calculation Logic:
- If the call time is more than 20 minutes AND the called area code is different from the customer’s area code, the call is charged at 2 cents per minute.
- If the call time is 20 minutes or less OR the called area code is the same as the customer’s area code, the call is charged at 13 cents per minute.
Display Information:
We need to display:
- Customer area code
- Customer phone number
- Called area code
- Called number
- Called time in minutes
- Total charge for the call
Example Input/Output:
- Input:
- Customer Area Code: 123
- Customer Phone Number: 4567890
- Called Area Code: 456
- Called Number: 1234567
- Call Time: 25 minutes
- Output:
- Customer Area Code: 123
- Customer Phone Number: 4567890
- Called Area Code: 456
- Called Number: 1234567
- Call Time: 25 minutes
- Total Charge: 50 cents (25 minutes * 2 cents per minute)
Flowchart:
Here’s how you can visualize the process in a flowchart format:
- Start: Initialize the program.
- Input Call Data: Collect the customer area code, phone number, called area code, called number, and call time.
- Check If Call Time > 20 Minutes:
- If No: Charge 13 cents per minute.
- If Yes: Check if Called Area Code is different from Customer’s Area Code.
- If Yes: Charge 2 cents per minute.
- If No: Charge 13 cents per minute.
- Calculate Total Charge: Multiply call time by appropriate rate.
- Display Information: Output the customer and call details along with the total charge.
- End: Terminate the program.
Flowchart Diagram Description:
- Start
- Input customer details (area code, phone number, called area code, called number, call time)
- Is the call time greater than 20 minutes?
- Yes: Is the called area code different?
- Yes: Charge 2 cents per minute
- No: Charge 13 cents per minute
- No: Charge 13 cents per minute
- Display details and total charge
- End
This structure ensures that every call is correctly processed and that the customer is charged according to the rules specified.
Explanation:
In the solution, we are implementing a program that processes each call’s details and calculates the total charge based on conditions (call time and area codes). The main logic involves comparing the call time with the 20-minute threshold and checking if the called area code is the same as the customer’s area code. Based on these comparisons, the program computes the charge and displays the required output.
By following these steps and flowchart logic, you ensure that the telephone company applies the correct rates to calls, ensuring accurate billing for the customer.