Answered step by step
Verified Expert Solution
Question
1 Approved Answer
#include using namespace std; / / Base class class Road { string name; int numberOfLanes; int maximumSpeed; public: Road ( string n , int l
#include
using namespace std;
Base class
class Road
string name;
int numberOfLanes;
int maximumSpeed;
public:
Roadstring nint lint s
name n;
ifl
numberOfLanes l;
else
int x;
whilex
cout
Enter valid number of lanes";
cinx;
numberOfLanes x;
ifs && s
maximumSpeed s;
else
int x;
whilex && x
cout
Enter valid maximum speed";
cinx;
maximumSpeed x;
void toString
cout
Road Name :
numberOfLanes l;
else
int x;
whilex
cout
Enter valid number of lanes";
cinx;
numberOfLanes x;
void setSpeedint s
condition for valid maximumSpeed
ifs && s
maximumSpeed s;
else
int x;
whilex && x
cout
Enter valid maximum speed";
cinx;
maximumSpeed x;
Getter function
string getName
return name;
int getNumberOfLanes
return numberOfLanes;
int getMaximumSpeed
return maximumSpeed;
;
TollRoad class inherit the Road class
Derived class
class TollRoad : public Road
int toll;
public:
parameterized constructor
TollRoadstring name,int lint sint t:Roadnamels pass value to base class constructor
condition for valid Toll value
ift
toll t;
else
int x;
whilex
cout
Enter toll value greater than : ;
cinx;
toll x;
setter function
void setTollint t
condition for valid Toll value
ift
toll t;
else
int x;
whilex
cout
Enter toll value greater than : ;
cinx;
toll x;
int getToll getter method
return toll;
void TolltoString to string method
toString;
cout
Toll Value :
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started