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. Instructions Ensure the file named Motorcycle.cppis open in your editor. 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. Write a public set method to set the value for sidecar. Write a public get method to retrieve the value of sidecar. 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". Open the file named MyMotorcycleClassProgram.cpp. In the MyMotorcycleClassProgram, 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 90 and motorcycleTwo’s maximum speed to 85. Set motorcycleOne’s current speed to 65 and motorcycleTwo’s current speed to 60. Accelerate motorcycleOne by 30 mph, and accelerate motorcycleTwo by 20 mph. Print the current speed of motorcycleOne and motorcycleTwo. 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. Execute the program by clicking the Run button at the bottom of the screen.     // Motorcycle.cpp #include "Vehicle.cpp" #include using namespace std; class Motorcycle:public Vehicle{ public: voidsetSidecar(bool); boolgetSidecar(); voidaccelerate(double); private: bool sidecar; }; voidMotorcycle::setSidecar(bool s){ sidecar=s; } boolMotorcycle::getSidecar(){ return sidecar; } voidMotorcycle::accelerate(double mph) { if(getSpeed() + mph using namespace std; int main() { Motorcycle motorcycleOne,motorcycleTwo; motorcycleOne.setSidecar(true); motorcycleTwo.setSidecar(false); motorcycleOne.setMaxSpeed(90); motorcycleTwo.setMaxSpeed(85); motorcycleOne.setSpeed(65); motorcycleTwo.setSpeed(60); motorcycleOne.accelerate(30); motorcycleTwo.accelerate(20); cout<<"MotorcycleOne speed:"<< motorcycleOne.getSpeed()<

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

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.

Instructions

  1. Ensure the file named Motorcycle.cppis 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.
  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 30 mph, 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: This motorcycle does not have a side car.
  15. Execute the program by clicking the Run button at the bottom of the screen.
     
     
    // Motorcycle.cpp
    #include "Vehicle.cpp"
    #include <iostream>
    using namespace std;
    class Motorcycle:public Vehicle{
    public:
    voidsetSidecar(bool);
    boolgetSidecar();
    voidaccelerate(double);
    private:
    bool sidecar;
    };
    voidMotorcycle::setSidecar(bool s){
    sidecar=s;
    }
    boolMotorcycle::getSidecar(){
    return sidecar;
    }
    voidMotorcycle::accelerate(double mph)
    {
    if(getSpeed() + mph <getMaxSpeed())
    setSpeed(getSpeed() + mph);
    else
    cout << "This motorcycle cannot go that fast." << endl;
    }
     
    // This program uses the programmer-defined Motorcycle class.
    #include "Motorcycle.cpp"
    #include <iostream>
    using namespace std;
    int main()
    {
    Motorcycle motorcycleOne,motorcycleTwo;
    motorcycleOne.setSidecar(true);
    motorcycleTwo.setSidecar(false);
    motorcycleOne.setMaxSpeed(90);
    motorcycleTwo.setMaxSpeed(85);
    motorcycleOne.setSpeed(65);
    motorcycleTwo.setSpeed(60);
    motorcycleOne.accelerate(30);
    motorcycleTwo.accelerate(20);
    cout<<"MotorcycleOne speed:"<< motorcycleOne.getSpeed()<<endl;
    cout<<"MotorcycleTwo speed:"<< motorcycleTwo.getSpeed()<<endl;
    if(motorcycleOne.getSidecar())
    cout<<"MotorcycleOne has a sidecar"<<endl;
    else
    cout<<"MotorcycleOne does not have a sidecar"<<endl;
    if(motorcycleTwo.getSidecar())
    cout<<"MotorcycleTwo has a sidecar"<<endl;
    else
    cout<<"MotorcycleTwo does not have a sidecar"<<endl;
     
    return0;
    }

 

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Data members
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education