Using Inheritance to Create a Derived Class in C++ Summary 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 objecta. and then set the Motorcycle's speed. accelerate the Motorcycle object. and check its sidecar status. Instructions 1. Ensure the file named Motorcycle.cpp is open in your editor. 2. Create the Motorcycle class by deriving it from the Vehicle class. Use a public derivation. 3. In the Motorcycle class. create a private attribute named sidecar. The sidecar attribute should be data type bool. 4. Write a public set method to set the value for sidecar. 5. Write a public get method to retrieve the value of sidecar. 6. 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 motoreycle cannot go that fast". 7. Open the file named MyMotorcycleClassProgram.opp. 8. In the MyMotoreycleClassProgram. create two Motorcycle objects named motoroycleOne and motorcyale Two. 9. Set the sidecar value of motorcycleone to true and the sidecar value of motoreycleTwo to false. 10. Set motoreycleOne's maximum speed to 90 and motorcyeleTwo's maximum speed to 85. 11. Set motorcycleone's current speed to 65 and motorcycleTwo's current speed to 60. 12. Accelerate motorcycleOne by 30 mph. and accelerate motoreycleTwo by 20 mph. 13. Print the current speed of motorcycleone and motorcycleTwo. 14. 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. 15. Execute the program by clicking the Run button at the bottom of the screen.
Using Inheritance to Create a Derived Class in C++ Summary 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 objecta. and then set the Motorcycle's speed. accelerate the Motorcycle object. and check its sidecar status. Instructions 1. Ensure the file named Motorcycle.cpp is open in your editor. 2. Create the Motorcycle class by deriving it from the Vehicle class. Use a public derivation. 3. In the Motorcycle class. create a private attribute named sidecar. The sidecar attribute should be data type bool. 4. Write a public set method to set the value for sidecar. 5. Write a public get method to retrieve the value of sidecar. 6. 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 motoreycle cannot go that fast". 7. Open the file named MyMotorcycleClassProgram.opp. 8. In the MyMotoreycleClassProgram. create two Motorcycle objects named motoroycleOne and motorcyale Two. 9. Set the sidecar value of motorcycleone to true and the sidecar value of motoreycleTwo to false. 10. Set motoreycleOne's maximum speed to 90 and motorcyeleTwo's maximum speed to 85. 11. Set motorcycleone's current speed to 65 and motorcycleTwo's current speed to 60. 12. Accelerate motorcycleOne by 30 mph. and accelerate motoreycleTwo by 20 mph. 13. Print the current speed of motorcycleone and motorcycleTwo. 14. 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. 15. Execute the program by clicking the Run button at the bottom of the screen.
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...
Related questions
Question
100%
here's the 3rd.
Vehicle.cpp
// Vehicle.cpp
#include <iostream>
using namespace std;
class Vehicle
{
public:
void setSpeed(double);
double getSpeed();
void accelerate(double);
void setFuelCapacity(double);
double getFuelCapacity();
void setMaxSpeed(double);
double getMaxSpeed();
private:
double fuelCapacity;
double maxSpeed;
double currentSpeed;
};
void Vehicle::setSpeed(double speed)
{
currentSpeed = speed;
return;
}
double Vehicle::getSpeed()
{
return currentSpeed;
}
void Vehicle::accelerate(double mph)
{
if(currentSpeed + mph < maxSpeed)
currentSpeed = currentSpeed + mph;
else
cout << "This vehicle cannot go that fast." << endl;
}
void Vehicle::setFuelCapacity(double fuel)
{
fuelCapacity = fuel;
}
double Vehicle::getFuelCapacity()
{
return fuelCapacity;
}
void Vehicle::setMaxSpeed(double max)
{
maxSpeed = max;
}
double Vehicle::getMaxSpeed()
{
return maxSpeed;
}
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images
Recommended textbooks for you
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 Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
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 Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
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
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY