Answered step by step
Verified Expert Solution
Link Copied!

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:
Road(string n,int l,int s){
name = n;
if(l>0){
numberOfLanes = l;
}else{
int x=0;
while(x<=0){
cout<<"
Enter valid number of lanes";
cin>>x;
}
numberOfLanes = x;
}
if(s>0 && s<=100){
maximumSpeed = s;
}else{
int x=0;
while(x>0 && x<=100){
cout<<"
Enter valid maximum speed";
cin>>x;
}
maximumSpeed = x;
}
}
void toString(){
cout<<"
Road Name : "<0){
numberOfLanes = l;
}else{
int x=0;
while(x<=0){
cout<<"
Enter valid number of lanes";
cin>>x;
}
numberOfLanes = x;
}
}
void setSpeed(int s){
// condition for valid maximumSpeed
if(s>0 && s<=100){
maximumSpeed = s;
}else{
int x=0;
while(x>0 && x<=100){
cout<<"
Enter valid maximum speed";
cin>>x;
}
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
TollRoad(string name,int l,int s,int t):Road(name,l,s){// pass value to base class constructor
// condition for valid Toll value
if(t>0){
toll = t;
}else{
int x=0;
while(x<=0){
cout<<"
Enter toll value greater than 0 : ";
cin>>x;
}
toll = x;
}
}
// setter function
void setToll(int t){
// condition for valid Toll value
if(t>0){
toll = t;
}else{
int x=0;
while(x<=0){
cout<<"
Enter toll value greater than 0 : ";
cin>>x;
}
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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2017 Skopje Macedonia September 18 22 2017 Proceedings Part 3 Lnai 10536

Authors: Yasemin Altun ,Kamalika Das ,Taneli Mielikainen ,Donato Malerba ,Jerzy Stefanowski ,Jesse Read ,Marinka Zitnik ,Michelangelo Ceci ,Saso Dzeroski

1st Edition

3319712721, 978-3319712727

More Books

Students also viewed these Databases questions