Question: C++ 12.2 Toll calculator Toll Calculator Write a program that incrementally calculates the toll amount for travel along a toll road or toll lane. The

C++

12.2 Toll calculator

Toll Calculator

Write a program that incrementally calculates the toll amount for travel along a toll road or toll lane. The toll amount is based on the time of day, day of the week, and number of persons in the vehicle. The initial version of the program calculates the toll amount for travel on a weekday based upon the toll schedule below. The table lists times in both am/pm format and 24-hour format. Table 3.9.1: Weekday toll schedule. Time (am/pm) Time (24 hour) Toll amount Before 6:00 am Before 6:00 1.55 6:00 am to 9:59 am 6:00 to 9:59 4.65 10:00 am to 5:59 pm 10:00 to 17:59 2.35 6:00 pm and after 18:00 and after 1.55 Feedback? The program gets the time of travel from the user using 24 hours format, and uses the hour to determine the toll amount. A multi-branch if-else statement is used to determine in which range the hour belongs and assigns tollAmount with the toll based on the table above, and outputs the toll.

Enter time of travel (HH:MM in 24 hour format): 9:30 Toll at 9:30 is 4.65

A toll road often has a different toll schedule for weekends and holidays than for weekdays. The table below lists the toll schedule for weekends and holidays. Table 3.9.2: Toll schedule for weekends and holidays. Time (am/pm) Time (24 hour) Toll amount Before 8:00 am Before 8:00 1.55 8:00 am to 11:59 am 8:00 to 11:59 3.05 12:00 pm to 3:59 pm 12:00 to 15:59 3.45 4:00 pm to 6:59 pm 16:00 to 18:59 3.60 7:00 pm to 9:59 pm 19:00 to 21:59 3.05 10:00 pm and after 22:00 and after 1.55

The revised program additionally gets the type of day from the user (0 for weekdays, and 1 for weekends or holidays). The program uses nested if-else statements to calculate the toll amount. The outer if-else checks if the today is a weekday or weekend/holiday. The nested if-else statements implement the respective toll schedules by determining the appropriate toll based on the hour of travel. The program also uses if-else statements to output the time of travel using am/pm format instead of 24-hour format.

Enter time of travel (HH:MM in 24 hour format): 10:45 Enter type of day (0 - weekday, 1 - weekend/holiday): 1 Toll at 10:45 am is 3.05

A toll road may have a discount for carpools, sometimes called high-occupancy vehicles (HOV). The following program uses if-else statement to adjust the toll amount based on the number of person in the vehicle. The carpool discount rules are: A carpool is 3 or more person per vehicle. The toll for carpools on weekdays between 6:00 am and 10:00 am is half the normal toll. Otherwise, the toll for carpools is 0 (as in free).

Enter time of travel (HH:MM in 24 hour format): 17:15 Enter type of day (0 - weekday, 1 - weekend/holiday): 0 Enter number of persons in vehicle: 3 Toll at 5:15 pm is 0

Enter time of travel (HH:MM in 24 hour format): 23:45 Enter type of day (0 - weekday, 1 - weekend/holiday): 0 Enter number of persons in vehicle: 2 Toll at 5:15 pm is $1.55

LAB

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!