Question: Write a code in C++ using the follwoing criteria INCLUDE DETAILED COMMENTING: In this assignment a class hierarchy is created with three classes. The three

Write a code in C++ using the follwoing criteria INCLUDE DETAILED COMMENTING:

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 ships name and the year it was built

CruiseShip 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 ships name and the maximum number of passengers.

CargoShip 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 ships 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.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!