Ask Question
13 February, 01:49

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.

+5
Answers (1)
  1. 13 February, 05:05
    0
    See explaination

    Explanation:

    Program source code below.

    #include "Motorcycle. cpp"

    #include

    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 () <
    cout<<"MotorcycleTwo speed:"<< motorcycleTwo. getSpeed () <
    if (motorcycleOne. getSidecar ())

    cout<<"MotorcycleOne has a sidecar"<
    else

    cout<<"MotorcycleOne does not have a sidecar"<
    if (motorcycleTwo. getSidecar ())

    cout<<"MotorcycleTwo has a sidecar"<
    else

    cout<<"MotorcycleTwo does not have a sidecar"<
    / / 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 0;

    }

    Motorcycle. cpp

    #include "Vehicle. cpp"

    #include

    using namespace std;

    class Motorcycle:public Vehicle{

    public:

    void setSidecar (bool);

    bool getSidecar ();

    void accelerate (double);

    private:

    bool sidecar;

    };

    void Motorcycle::setSidecar (bool s) {

    sidecar=s;

    }

    bool Motorcycle::getSidecar () {

    return sidecar;

    }

    void Motorcycle::accelerate (double mph)

    {

    if (getSpeed () + mph < getMaxSpeed ())

    setSpeed (getSpeed () + mph);

    else

    cout << "This motorcycle cannot go that fast." << endl;

    }
Know the Answer?
Not Sure About the Answer?
Find an answer to your 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 ...” in 📘 Engineering if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers