Developing Code

Job ID: 35151304

Budget: $10 – $30 USD

You do NOT need to write a driver. Use the one provided in the template. Name it VehicleMain.cpp
You are given VehicleHeader.h, Vehicle.cpp // The entire class is given to you
You are given PlaneHeader.h and CarHeader.h // Headers of derived classes given
You need to MODIFY methods in Plane.cpp and Car.cpp to induce polymorphic behavior

Vehicle
-year: int //year of manufacture
-speed: int // miles per hour
-type: string // “Vehicle” or “Plane” or “Car”
-model: string // model (for Car it could be Honda etc, for Plane it can be Boeing etc)


+Vehicle();
+Vehicle(int year, int speed, string type, string model);
+setSpeed(int speed): void
+setYear(int year): void
+setModel(string model): void
+setType(string type): void
+getSpeed(): int
+getYear(): int
+getType(): string
+getModel(): string
+addSpeed(int s): void // just keep this method empty for now
+serveDrinks():string // returns “Drinks served only on Planes”
string toString(): string // *** implement this Polymorphically


UML of Plane Class
Plane (Inherits from Vehicle)

+ Plane();
+Plane(int year, int speed, string type, string model, int altitude);
+getAltitude(): int // returns current height of plane
+setAltitude(int height): void // sets the altitude in feet provided it is a positive number <300000
+addSpeed(int s): void // ** implement this polymorphically
// the value s should be greater than 0 and speed of the plane should never exceed 1000 miles per hour. If s is not an acceptable value, throw exception and exit.
+serveDrinks():string // returns “Water and Apple Juice Available

+toString():string // ***implement this Polymorphically to display the plane object details


Car (inherits from Vehicle)
-wheelSize : int // size of car wheels (this field is not there in Vehicle or Plane)
+ Car();
+Plane(int year, int speed, string type, string model, int wheelSize);
+addSpeed(int s): void //** implement this polymorphically
// the value s should be greater than 0 and speed of the plane should never exceed 100 miles per hour. If s is not an acceptable value, throw exception and exit.

+serveDrinks():string // ** implement this polymorphically. It should say “Food and Drinks are not permitting in a Car”
+getWheelSize(): int // returns the wheelSize of the car.
+toString(): String // return the string of the Car object. Look at output for format


Specifications:

1) Upgrade the Plane Class that inherits from the Vehicle class and that is based on the UML given above
2) Implement the addSpeed, toString, and serveDrinks method to exhibit polymorphic behavior
3) Experiment with different speeds, negative and too large values for car and plane
4) Test your program with the driver given to you to see that it matches the output given
5) Examine the program to see that
a) The declarations of car and plane have changed to type b)
Shared_ptr<Vehicle> car = make_shared<Car>(); instead of
Shared_ptr<Car> car = make_shared<Car>();
b) The getAltitude (for plane) and getWheelSize (for car) methods can therefore no longer be called because they are not defined in the Vehicle base class
c) The toString, addSpeed and serveDrinks methods behave polymorphically
d) Note that even when defined polymorphically, if one derived class does not implement that instance method, then the base class behavior will be exhibit.
Related categories: UML Design C++ Programming Computer Science