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:
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:
- 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.
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images