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.cpp is 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. Tasks: Correctly ouputs the current speed. Keywords must have: The current speed of motorcycleOne is 65 The current speed of motorcycleTwo is 80 Correctly outputs if speed capability is exceeded. Keywords must have This motorcycle cannot go that fast Correctly outputs if motorcycle has a sidecar. Keywords must have: This motorcycle has a side car This motorcycle does not have a side car Use the instructions in each file: First File: Mortorcycle.cpp // Motorcycle.cpp #include "Vehicle.cpp" #include using namespace std; // Write the Motorcycle class here Second File: MyMotorcycleClassProgram.cpp. // This program uses the programmer-defined Motorcycle class. #include "Motorcycle.cpp" #include using namespace std; int main() { // 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; } Third File: Vehicle.cpp // Vehicle.cpp #include using namespace std; class Vehicle { public: void setSpeed(double); double getSpeed(); void accelerate(double); void setFuelCapacity(double); double getFuelCapacity(); void setMaxSpeed(double); double getMaxSpeed(); private: double fuelCapacity; double maxSpeed; double currentSpeed; }; void Vehicle::setSpeed(double speed) { currentSpeed = speed; return; } double Vehicle::getSpeed() { return currentSpeed; } void Vehicle::accelerate(double mph) { if(currentSpeed + mph < maxSpeed) currentSpeed = currentSpeed + mph; else cout << "This vehicle cannot go that fast." << endl; } void Vehicle::setFuelCapacity(double fuel) { fuelCapacity = fuel; } double Vehicle::getFuelCapacity() { return fuelCapacity; } void Vehicle::setMaxSpeed(double max) { maxSpeed = max; } double Vehicle::getMaxSpeed() { return maxSpeed; }
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.cpp is 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. Tasks: Correctly ouputs the current speed. Keywords must have: The current speed of motorcycleOne is 65 The current speed of motorcycleTwo is 80 Correctly outputs if speed capability is exceeded. Keywords must have This motorcycle cannot go that fast Correctly outputs if motorcycle has a sidecar. Keywords must have: This motorcycle has a side car This motorcycle does not have a side car Use the instructions in each file: First File: Mortorcycle.cpp // Motorcycle.cpp #include "Vehicle.cpp" #include using namespace std; // Write the Motorcycle class here Second File: MyMotorcycleClassProgram.cpp. // This program uses the programmer-defined Motorcycle class. #include "Motorcycle.cpp" #include using namespace std; int main() { // 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; } Third File: Vehicle.cpp // Vehicle.cpp #include using namespace std; class Vehicle { public: void setSpeed(double); double getSpeed(); void accelerate(double); void setFuelCapacity(double); double getFuelCapacity(); void setMaxSpeed(double); double getMaxSpeed(); private: double fuelCapacity; double maxSpeed; double currentSpeed; }; void Vehicle::setSpeed(double speed) { currentSpeed = speed; return; } double Vehicle::getSpeed() { return currentSpeed; } void Vehicle::accelerate(double mph) { if(currentSpeed + mph < maxSpeed) currentSpeed = currentSpeed + mph; else cout << "This vehicle cannot go that fast." << endl; } void Vehicle::setFuelCapacity(double fuel) { fuelCapacity = fuel; } double Vehicle::getFuelCapacity() { return fuelCapacity; } void Vehicle::setMaxSpeed(double max) { maxSpeed = max; } double Vehicle::getMaxSpeed() { return maxSpeed; }
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
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
- Ensure the file named Motorcycle.cpp is 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.
Tasks:
- Correctly ouputs the current speed. Keywords must have:
The current speed of motorcycleOne is 65The current speed of motorcycleTwo is 80
- Correctly outputs if speed capability is exceeded. Keywords must have
This motorcycle cannot go that fast
- Correctly outputs if motorcycle has a sidecar. Keywords must have:
This motorcycle has a side carThis motorcycle does not have a side car
Use the instructions in each file:
First File: Mortorcycle.cpp
// Motorcycle.cpp
#include "Vehicle.cpp"
#include <iostream>
using namespace std;
// Write the Motorcycle class here
Second File: MyMotorcycleClassProgram.cpp.
// This program uses the programmer-defined Motorcycle class.
#include "Motorcycle.cpp"
#include <iostream>
using namespace std;
int main()
{
// 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;
}
Third File: Vehicle.cpp
// Vehicle.cpp
#include <iostream>
using namespace std;
class Vehicle
{
public:
void setSpeed(double);
double getSpeed();
void accelerate(double);
void setFuelCapacity(double);
double getFuelCapacity();
void setMaxSpeed(double);
double getMaxSpeed();
private:
double fuelCapacity;
double maxSpeed;
double currentSpeed;
};
void Vehicle::setSpeed(double speed)
{
currentSpeed = speed;
return;
}
double Vehicle::getSpeed()
{
return currentSpeed;
}
void Vehicle::accelerate(double mph)
{
if(currentSpeed + mph < maxSpeed)
currentSpeed = currentSpeed + mph;
else
cout << "This vehicle cannot go that fast." << endl;
}
void Vehicle::setFuelCapacity(double fuel)
{
fuelCapacity = fuel;
}
double Vehicle::getFuelCapacity()
{
return fuelCapacity;
}
void Vehicle::setMaxSpeed(double max)
{
maxSpeed = max;
}
double Vehicle::getMaxSpeed()
{
return maxSpeed;
}
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 4 images
Knowledge Booster
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.Recommended textbooks for you
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)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
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)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education