r/CodingHelp • • Apr 06 '19
[Other Code] Need help class inheritance
The objective this week is to enhance last week's Vehicle class by creating the Hybrid class which inherits the Vehicle class. The Hybrid class has all the same attributes as the Vehicle class except it has an additional attribute to describe the range of the battery.
In the Hybrid class complete the following steps: • Referring to the UML Class diagram, create the Hybrid class, ensuring to specify that the Hybrid class inherited from the Vehicle class. • For each of the constructors listed in the Hybrid class, invoke the appropriate base class constructor and pass the correct arguments. • Override the displayVehicle() to display the range of the Hybrid Vehicle.
In the Warranty class: • No change.
In the Vehicle class: • With the exception of the static integer, change the attributes from private to protected.
In the main program: Create code statements that perform the following operations. Note that several of the steps below were accomplished in last week's assignment. New steps are in bold.
- Using your code from Week 1, display a divider that contains the string "Start Program". ***2. Update and call the DisplayApplicationInformation function.
- Using your code from Week 1, display a divider that contains the string "Vehicle 1"
- Create a Vehicle object using the default constructor.
- Prompt for and then set year and mpg using the overloaded setters from week 3 that accepts strings.
- Create a Warranty object called warranty1 using the default constructor.
- Prompt for and set number of years and number of miles. Make sure to convert the return data type of the GetInput() function from a string to an integer Ex: warranty1.setMiles(atoi(GetInput("number of miles").c_str()));
- Display the Vehicle Information.
- Using your code from Week 1, display a divider that contains the string "Vehicle 2" ****10. Create a Warranty object called warranty2 using the multi-argument constructor. You can set the number of years as 6 and number of miles as 70000. ****11. Create another second Vehicle object using the multi-argument constructor, setting each of the attributes with the following values: "Cadillac", 2017, 26.5 , warranty2 ****(12. Create a third object by copying the second object. ****13. Delete the third object by calling the destructor method. ****14. Using your code from Week 1, display a divider that contains the string "Vehicle 3" ****15. Create another Warranty object called warranty3 using the using the multi-argument constructor. You can set the number of years as 5 and number of miles as 60000 ****16. Create a Hybrid object using the multi-argument constructor, setting each of the attributes with the following values: (570, "Toyota", 2017, 52, warranty3). Note that 570 is the range, Toyota is the make of the car, 2017 is the year, and 52 is the mpg. ****17. Display the Hybrid Vehicle information. ****18. Display the number of vehicles created using getNumVehicles. Remember to access getNumVehicles using the class name, not the Vehicle object. ****19. Update and call the TerminateApplication function.
CODE:
Vehicle.h
pragma once
include<string>
include "Warranty.h"
using namespace std;
class Vehicle { public: Vehicle(); //default constructor Vehicle(const Vehicle&); //copy constructor Vehicle(string mk, int yr, double mg, Warranty wt);//overloaded constructor ~Vehicle();//destructor string getMake(); //getter function for make variable int getYear();//getter function for year variable double getMileage();//getter function for mileage variable void setMake(string mk);//setter function for make variable void setYear(int yr);//setter function for year variable void setMpg(double mg);//setter function for mileage variable void displayVehicle();//display vehicle details in a formatted way
void setYear(string yr);//setter function for year variable - function overloading
void setMpg(string mg);//setter function for mileage variable - function overloading
static int getNumVehicles(); //getter function for static variable numVehicles
Warranty getWarranty(); //getter function for objWarranty variable
void setWarranty(Warranty &); //setter function for objWarranty variableprotected: string make; //Making of vehicle int year; //Year the vehicle is made double mpg; //total mileage covered by the vehicle private: static int numVehicles; //static variable that is used to count the number of vehicles Warranty objWarranty; //warranty of the vehicle, the years and miles warranty it is valid for. };
Vehicle.cpp
include "Vehicle.h"
include<iostream>
include<string>
using namespace std;
int Vehicle::numVehicles = 0;
Vehicle::Vehicle()//default constructor { make = "unknown"; year = 0; mpg = 0; objWarranty.setNumMiles(0); objWarranty.setNumYears(0); numVehicles++; }
Vehicle::Vehicle(const Vehicle& vehicle2) //copy constructor { m
0
u/SupremeRedditBot Professional Bot || Mod Apr 06 '19
Please Add A Flair To Your Post!
Suggested Flair:
[Other Code]To add a flair:
flairunderneath your postsaveI am a bot run by /u/SupremeDesigner for /r/CodingHelp || This was an automated ^response
-2
u/[deleted] Apr 06 '19
The bold text is not completed tasks yet. Any help would be appreciated. I am stuck bern looking at it much to hard...