In C++,  design and implement two classes in an inheritance hierarchy, according to the requirements listed below, and then demonstrate their capabilities through a short program.  Program Requirements:

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
100%

Hello, this is one question and not multiple questions. Below is the question.

 

In C++,  design and implement two classes in an inheritance hierarchy, according to the requirements listed below, and then demonstrate their capabilities through a short program. 

Program Requirements:

  1. Design a base class, Road, with the following members:
  • Attributes for storing the road’s name, number of lanes, and maximum speed limit.
  • A three-parameter constructor to initialize the three attributes.
  • Accessors and Mutators (Gets and Sets) for each attribute.
  • Input Validation: You should ensure that the number of lanes is always a value greater than 0, and that the maximum speed limit is a value between 0 and 100 MPH. This input validation should apply to both the 3-parameter constructor and the individual accessor functions.
  • A display function that prints the road’s information in a single line format (see the Sample Output for a formatting example).

 

b. Design a derived class, TollRoad, which inherits from Road. It should have the following members:

  • An attribute for storing the toll for using the road.
  • A 4-parameter constructor to initialize the three attributes of the base class, as well as the toll.
  • Accessor and Mutator methods for the toll.
  • Input Validation: You should ensure that the toll is a value greater than 0.0. This validation

should apply to both the 4-parameter constructor as well as the individual accessor.

  • An overridden display function that displays the information of the TollRoad in a two-line format, where the first line displays basic Road information, and a second line specifies

the current toll (see Sample Output for a formatting example).

 

C. In the main, you should demonstrate the capabilities of your classes by allowing the user to create new roads (or toll roads), as well as display a list of all previously created roads and their information (via their display function).

  • Your program should allow the user to add at least ten (10) Roads and/or TollRoads, which

should be represented in a single array. For an additional challenge, you may choose to remove that limit and support any number of roads, but this is not a requirement of the exam.

  • The Sample Output provided below is an example of the intended functionality. Your output

does not need to be an exact match for the sample, but should fulfill all the same tasks.

 

~~~ Main Menu ~~~~~
1) Add a new Road
2) View current Roads
3) Exit Program
>> 1
Registering a new road...
Enter the road's name: I-35
How many lanes does I-35 have? 6
What is the maximum speed limit (in MPH) for I-35? 65
Is I-35 a toll road? (Y/N) N
I-35 has been successfully added.
~~~~~ Main Menu ~~~~~
1) Add a new Road
2) View current Roads
3) Exit Program
>> 1
Registering a new road...
Enter the road's name: SH 288
How many lanes does SH 288 have? 4
What is the maximum speed limit (in MPH) for SH 288? 80
Is SH 288 a toll road? (Y/N) Y
Enter the standard toll for use of SH 288: 2.50
SH 288 has been successfully added.
~~~~~ Main Menu ~~~~~
1) Add a new Road
2) View current Roads
3) Exit Program
>> 2
Listing current roads...
1) I-35 is a standard road with 6 lanes, and a max permissible speed of 65.
2) SH 288 is a toll road with 4 lanes, and a max permissible speed of 80.
The current toll to use SH 288 is $2.50.
~~~~~ Main Menu ~~~~~
1) Add a new Road
2) View current Roads
3) Exit Program
~~~~~ Main Menu ~~~~~
1) Add a new Road
2) View current Roads
3) Exit Program
>> 1
Registering a new road...
Enter the road's name: SH 288
How many lanes does SH 288 have? 0
What is the maximum speed limit (in MPH) for SH 288? 500
Is SH 288 a toll road? (Y/N) Y
Enter the standard toll for use of SH 288: -2.50
Number of lanes must be greater than 0.
Please enter the number of lanes: 4
Maximum speed limit must be greater than 0 and no more than 100 MPH.
Please enter the maximum speed limit: -200
Maximum speed limit must be greater than 0 and no more than 100 MPH.
Please enter the maximum speed limit: 65
Toll Roads must have a toll of greater than $0.00.
Please enter a new value for the toll: 3.20
SH 288 has been successfully added.
~~~~~ Main Menu ~~~~~
1) Add a new Road
2) View current Roads
3) Exit Program
>> 2
Listing current roads...
1) SH 288 is a toll road with 4 lanes, and a max permissible speed of 65.
The current toll to use SH 288 is $3.20.
~~~~~ Main Menu ~~~~~
1) Add a new Road
2) View current Roads
3) Exit Program
>>
Transcribed Image Text:~~~ Main Menu ~~~~~ 1) Add a new Road 2) View current Roads 3) Exit Program >> 1 Registering a new road... Enter the road's name: I-35 How many lanes does I-35 have? 6 What is the maximum speed limit (in MPH) for I-35? 65 Is I-35 a toll road? (Y/N) N I-35 has been successfully added. ~~~~~ Main Menu ~~~~~ 1) Add a new Road 2) View current Roads 3) Exit Program >> 1 Registering a new road... Enter the road's name: SH 288 How many lanes does SH 288 have? 4 What is the maximum speed limit (in MPH) for SH 288? 80 Is SH 288 a toll road? (Y/N) Y Enter the standard toll for use of SH 288: 2.50 SH 288 has been successfully added. ~~~~~ Main Menu ~~~~~ 1) Add a new Road 2) View current Roads 3) Exit Program >> 2 Listing current roads... 1) I-35 is a standard road with 6 lanes, and a max permissible speed of 65. 2) SH 288 is a toll road with 4 lanes, and a max permissible speed of 80. The current toll to use SH 288 is $2.50. ~~~~~ Main Menu ~~~~~ 1) Add a new Road 2) View current Roads 3) Exit Program ~~~~~ Main Menu ~~~~~ 1) Add a new Road 2) View current Roads 3) Exit Program >> 1 Registering a new road... Enter the road's name: SH 288 How many lanes does SH 288 have? 0 What is the maximum speed limit (in MPH) for SH 288? 500 Is SH 288 a toll road? (Y/N) Y Enter the standard toll for use of SH 288: -2.50 Number of lanes must be greater than 0. Please enter the number of lanes: 4 Maximum speed limit must be greater than 0 and no more than 100 MPH. Please enter the maximum speed limit: -200 Maximum speed limit must be greater than 0 and no more than 100 MPH. Please enter the maximum speed limit: 65 Toll Roads must have a toll of greater than $0.00. Please enter a new value for the toll: 3.20 SH 288 has been successfully added. ~~~~~ Main Menu ~~~~~ 1) Add a new Road 2) View current Roads 3) Exit Program >> 2 Listing current roads... 1) SH 288 is a toll road with 4 lanes, and a max permissible speed of 65. The current toll to use SH 288 is $3.20. ~~~~~ Main Menu ~~~~~ 1) Add a new Road 2) View current Roads 3) Exit Program >>
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY