Ask Question
17 August, 06:42

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. 17 August, 06:52
    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 the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers