Question: ` ` ` @ + Vehicle.cpp > g getMaxSpeed ( ) 4 7 void Vehicle::setMaxSpeed ( double max ) { maxSpeed = max; } double
@ Vehicle.cpp g getMaxSpeed
void Vehicle::setMaxSpeeddouble max
maxSpeed max;
double Vehicle::getMaxSpeed
return maxSpeed;
cdot Motorcycle.cpp
Motorcycle.cpp
#include "Vehicle.cpp
#include
using namespace std;
Write the Motorcycle class herd
@ MyMotorcycleClassProgram.cpp main
This program uses the programmerdefined Motorcycle class.
#include "Motorcycle.cpp
#include
using namespace std;
int main
Create Motorcyle objects here
Create a boolean variable for side car status
Set side car status here
Set maximum speed here
Set current speed here
Accelerate motorcyles here
Display current speed here
Determine side car status and display results
return ;
Your Tasks
In this lab, you create a derived class from a base class, and then use the derived class in a C program. The program should create two Motorcycle objects, and then set the Motorcycle's speed, accelerate the Motorcycle object, and check its sidecar status. Use the Vehicle and Automobile classes that you worked with earlier in this chapter as a guide.
Instructions
Open the file named Motorcycle.cpp Create the Motorcycle class by deriving it from the Vehicle class. Use a public derivation
Task : Create the Motorcycle class by deriving it from the Vehicle class. Use a public derivation.
In the Motorcycle class, create a private attribute named sidecar. The sidecar attribute should be data type bool.
Task : Write a public set and get methods for the sidecar attribute. Task : Write a public accelerate method. This method overrides the accelerate method inherited from the Vehicle class. Change the message in the accelerate method so the following is displayed when the Motorcycle tries to accelerate beyond its maximum speed:
"This motorcycle cannot go that fast".
In the MyMotorcycleClassProgram.cpp create two Motorcycle objects named motorcycleOne and motorcycleTwo. Set the sidecar value of motorcycleOne to true and the sidecar value of motorcycleTwo to false. Set motorcycleOne's maximum speed to and motorcycleTwo's maximum speed to Set motorcycleOne's current speed to and motorcycleTwo's current speed to Accelerate motorcycleOne by mph and accelerate motorcycleTwo by mph Print the current speed of motorcycleOne and motorcycleTwo.
Task : Determine if motorcycleOne and motorcycleTwo have sidecars. If yes, display the following: "This motorcycle has a side car". If not, display the following: "This motorcycle does not have a side car".
An example of the program is shown below:
This motorcycle cannot go that fast
The current speed of motorcycleOne is
The current speed of motorcycleTwo is
This motorcycle has a side car
This motorcycle does not have a side car
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
