Ask Question
10 October, 02:36

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.

+1
Answers (1)
  1. 10 October, 02:45
    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?
Get 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 there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers