programming with Light Commenting Through Code Project School

Question Description

In this assignment a class hierarchy is created with three classes. The three classes are described below.

Ship class (include Ship.h and Ship.cpp)

  • Contains data members for the following
    • String for name of the ship
    • Integer for the year the ship was built
  • Constructor with parameters
  • Accessors and mutators for the data members
  • A Virtual print function that displays the ship’s name and the year it was built

CruiseShip (include CuriseShip.h and CruiseShip.cpp) class that is derived from the Ship class.

  • Contains data members for the following
    • Integer for the maximum number of passengers
  • Constructor
  • Accessor and mutator for the data member
  • A print function that overrides the print function in the base class. This print function should display only the ship’s name and the maximum number of passengers.

CargoShip (include CargoShip.h and CargpShip.cpp) class that is derived from Ship class.

  • Contains data members for the following
    • Integer for the cargo capacity in tonnage
  • Constructor
  • Accessor and mutator for the data member

A print function that overrides the print function in the base class. This print function should display only the ship’s name and the cargo capacity.

Main should create an array of Ship pointers. The array should be able to hold six elements. The array elements should be initialized with the addresses of dynamically allocated Ship, CruiseShip, and CargoShip objects. The program should then have two methods that is passed the array of Ship pointers (the array), one method will iterate thru the array calling the print method. The other method will determine which ship is older. The array should have two instances of each of the classes.