Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Explain why this is true (no calculations are needed).

Answered: 1 week ago

Question

3. What strategies might you use?

Answered: 1 week ago

Question

3. Write a policy statement to address these issues.

Answered: 1 week ago