Use public inheritance to make polymorphic class hierarchies via the use of virtual functions. Reading Assignment Chapter 13 Lab 6 - 1 Create a class hierarchy starting with a “Vehicle” class. Create a dynamic program through the use of virtual functions. Vehicle.h The “Vehicle” class should have the following data members A dynamic string (char*) for the type of Vehicle A float for its speed Declare the following methods Default constructor that can take two arguments Trilogy (copy constructor, assignment operator, and destructor) for dynamic memory Show – to display the information *must be virtual Ask – to get the user-input *must be virtual Vehicle.cpp Define the methods prototyped in Vehicle.h Car.h Declare the “Car” class and derive (inherit) publicly from “Vehicle” This class should have the following data members A float for miles per gallon A dynamic string (char*) for its model (Corvette, Civic, etc.)
Declare the following methods Default constructor that can take four arguments (remember you’ve inherited two from “Vehicle”) Trilogy (copy constructor, assignment operator, and destructor) for dynamic memory Show – to display the information (make sure to display “Vehicle”’s info as well Ask – to get the user-input (make sure to ask for “Vehicle”’s info as well Car.cpp Define the methods prototyped in Car.h Ship.h Declare the “Ship” class and derive (inherit) publicly from “Vehicle” This class should have the following data members An int for its crew (the number of people needed to man the ship) A dynamic string (char*) for its title (USS Ulysses, USS Enterprise, etc.) Declare the following methods Default constructor that can take four arguments (remember you’ve inherited two from “Vehicle”) Trilogy (copy constructor, assignment operator, and destructor) for dynamic memory Show – to display the information (make sure to display “Vehicle”’s info as well Ask – to get the user-input (make sure to ask for “Vehicle”’s info as well Ship.cpp Define the methods prototyped in Ship.h main.cpp Create an array of 5 “Vehicle” pointersLoop 5 times, asking the user (via a menu) what type of Vehicle they would like to createAllocate the appropriate vehicle and Ask for user-inputAfter all 5 vehicles have been input, display them via the overridden Show methodVehicle Car Ship What would you like to create: 2 Type: Honda
Get Free Quote!
288 Experts Online