Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
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 nowThis is a popular solution!
Step by stepSolved 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.Similar questions
- You need to design this class. It represents each food wastage entry recorded by the user through the form on the webpage (frontend). If you notice the form on the webpage, you’ll see that each FoodWastageRecord will have the following as the data members aka member variables. Date (as string) Meal (as string) Food name (as string) Quantity in ounces (as double) Wastage reason (as string) Disposal mechanism (as string) Cost (as double) Each member variable comes with its accessor/mutator functions. food_wastage_record.hpp class FoodWastageRecord { public: void SetDate(const std::string &date); void SetMeal(const std::string &meal); void SetFoodName(const std::string &food_name); void SetQuantityInOz(double qty_in_oz); void SetWastageReason(const std::string &wastage_reason); void SetDisposalMechanism(const std::string &disposal_mechanism); void SetCost(double cost); std::string Date() const; std::string Meal() const; std::string FoodName() const;…arrow_forwardDeclaring a variable with only "type" is sufficient. The data type and other characteristics of a variable may be used to locate it. The next step is to figure out how to use this framework to describe any variable.arrow_forwardAs the first step in writing an application for the local book store, we will design and implement a Book class that will define the data structure of the application. Each book has a name, author, type (paperback, hardback, magazine), integer ID and pageCount. Provide some data validation in the appropriate method to ensure that the ID and pageCount are not negative. Design and implement a Book class with separation, i.e., separate all functions and methods into both the prototype and an implementation below the main. Provide constructor methods for Book(void), Book(name, author), and one for all components Book(name, author, type, ID, pageCount) Provide accessor (get and set) methods for each property as well as a display method. Provide data validation for the ID and pageCount in the appropriate methods. Provide a method to calculate the cost for buying books (with a 7.75% sales tax) according to the following chart: Hardcover: $29.95 per book Paperback:…arrow_forward
- 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…arrow_forwardClass Circle A Circle will have a radius. The class will be able to keep track of the number of Circle objects created. It will also hold the total of the circumferences of all the Circle objects created. It will allow a client to create a Circle, passing in a double value for the radius into the Circle constructor. If the value for the radius that is passed in is 0 or negative, then the radius will be set to a value of 999. The constructor should add 1 to the count of the number of Circles created. The constructor should call a method to calculate the circumference and then add the circumference for that object to an accumulator. In addition to the constructor, the Circle class must have the following methods that return a boolean value: isCongruent(Circle c) – Compares two Circle objects to determine if they are congruent (radii are equal). isValid() – the radius may not be 0 or negative. equals (Triangle t) – compares two Triangle objects…arrow_forwardCreate a Ferret class with properties name and weight passed to the constructor.arrow_forward
- How do I create this class in Java? Contact Class Requirements The contact object shall have a required unique contact ID string that cannot be longer than 10 characters. The contact ID shall not be null and shall not be updatable. The contact object shall have a required firstName String field that cannot be longer than 10 characters. The firstName field shall not be null. The contact object shall have a required lastName String field that cannot be longer than 10 characters. The lastName field shall not be null. The contact object shall have a required phone String field that must be exactly 10 digits. The phone field shall not be null. The contact object shall have a required address field that must be no longer than 30 characters. The address field shall not be null.arrow_forwardAdd 2 constructors to the Course class. One that takes no arguments and initializes the data to all 0’s and “” (empty strings). And one constructor that takes all 4 arguments, one argument for each property and then sets the properties to these arguments that are passed in. Lastly change the main to use these new Constructors. You will not need to call the set functions any more, but do not remove the set functions from your class. Main Code à Course c1; c1 = new Course(323, “Intro to Php”, “Intro to Php Programming”, 4); c1.display(); Problem #2: Do the same as above for the Account class. Problem #3: Do the same as above for the Person class. Below is my Course code public class Course { int Courzeld; String CourteName; String Description; int creditHours; void display() { System.out.println("Course ID: " + Courzeld); System.out.println("Course Name: " + CourteName); System.out.println("Description: " + Description);…arrow_forward
arrow_back_ios
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
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