Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

can an expert please help me get this code done Using Inheritance to Create a Derived Class in C++ Summary In this lab, you create

can an expert please help me get this code done image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
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 Ct+ program. The program should create two Motorcycle objects, 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 motorcycle cannot go that fast". 7. Open the file named MyMotorcycleClassProgram.cpp. 8. In the MyMotorcycleClassProgram, create two Motorcycle objects named motorcycleOne and motorcycleTwo. 9. Set the sidecar value of motorcycleOne to true and the sidecar value of motorcycleTwo to false. Using Inheritance to Create a Derived Class in C++ 5. Write a pubilc get metnoa to retrieve the value or 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 motorcycle cannot go that fast". 7. Open the file named MyMotorcycleClassProgram.cpp. 8. In the MyMotorcycleClassProgram, create two Motorcycle objects named motorcycleOne and motorcycleTwo. 9. Set the sidecar value of motorcycleOne to true and the sidecar value of motorcycleTwo to false. 10. Set motorcycleOne's maximum speed to 90 and motorcycleTwo's maximum speed to 85. 11. Set motorcycleOne's current speed to 65 and motorcycleTwo's current speed to 60. 12. Accelerate motorcycleOne by 30mph, and accelerate motorcycleTwo 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: Ths motorcycle does not have a side car. 15. Execute the program by clicking the Run button at the bottom of the screen. 1 // Motorcycle.cpp 2 \#include "Vehicle.cpp" 3 \#include iostream 4 using namespace std; 5 6 // Write the Motorcycle class here 7 Vehicle.cpp // Vehicle.cpp \#include iostream using namespace std; 4 class Vehicle 5\{ return; 3 double Vehicle:: getSpeed() \{ return currentSpeed; \} 31 void Vehicle: :accelerate(double mph) 32\{ 33 if(currentSpeed +mph

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_2

Step: 3

blur-text-image_3

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

The Database Experts Guide To Database 2

Authors: Bruce L. Larson

1st Edition

0070232679, 978-0070232679

More Books

Students also viewed these Databases questions