Purpose: Implement inheritance and polymorphism
Due: 11:59 PM on the specified day, using the turnin script. Late submissions will not be accepted.
Setup and test turnin. Inability to use turnin is not an excuse for late submission.
Description: Create a class hierarchy consisting of several classes derived directly or indirectly from a base class.
There are many kinds of vehicles commonly used in society. In particular, on city streets one can find several types of vehicles, including cars, trucks, motorcycles, and bicycles. For this project, you will create a Vehicle base class, and derive classes for trucks, cars and motorcycles from it. You will also write an application to test your program.
Write an abstract class Vehicle,
with data attributes location, color, typeOfVehicle, and model
(location is a point in 2-dimensional Cartesian space, and should be declared
as an object of either a pre-existing point type, or one you write). It will
have sets and gets for these attributes. Include an enumeration type named VehicleType
with elements car, truck, and motorcycle. The typeOfVehicle
attribute will be of type VehicleType. , The class has a constructor
that takes a parameter for each of these data members that calls the
corresponding sets. This class also has attributes for average speed and
destination (an int we may use later). These attributes have pure virtual sets
and gets, as they will be implemented differently, depending upon what kind of
vehicle is instantiated. Finally, it has a print() function that outputs
the location, color, typeOfVehicle, and model in a
cogent manner. Note that the Vehicle class, being abstract, cannot
itself be instantiated.
Next, write subclasses of Vehicle for each of Car, Truck, and Motorcycle. Each of these has a set and get for the average speed and destination. Their constructors pass the parameters for location, color, typeOfVehicle, and model to the superclass, and set the average speed and destination according to rules to be specified below. It also overrides the print() function, which prints its attributes while incorporating a call to the superclass’ print().
Finally, write an application that reads information from a file (specified below), instantiates vehicles accordingly in a vector of Vehicle *, and prints the info for each vehicle by calling the proper print(), using polymorphism.
Notes:
· Proper documentation and style is expected. The application must be modularly designed.
· The print() routine takes an ostream, the destination, as a parameter.
· Average speed of a vehicle is set to a random value (type int) within the following ranges, according to vehicle type:
· The format of the data file is as follows (one line per vehicle):
Turnin: Class code files (same name as class as specified herein), application (named p1.cpp), and a correctly written, working makefile.