Question: Ship_app.cpp #include #include #include Ship.h #include CruiseShip.h #include CargoShip.h using namespace std; int main() { // Create an array of Ship pointers, initialized with //

 Ship_app.cpp #include #include #include "Ship.h" #include "CruiseShip.h" #include "CargoShip.h" using namespace

std; int main() { // Create an array of Ship pointers, initialized

with // the addresses of 3 dynamically allocated objects. Ship *ships[3] =

{ new Ship("Lolipop", "1960"), new CruiseShip("Disney Magic", "1998", 2400), new CargoShip("Black Pearl",

Ship_app.cpp

#include

#include

#include "Ship.h"

#include "CruiseShip.h"

#include "CargoShip.h"

using namespace std;

int main()

{

// Create an array of Ship pointers, initialized with

// the addresses of 3 dynamically allocated objects.

Ship *ships[3] = { new Ship("Lolipop", "1960"),

new CruiseShip("Disney Magic", "1998", 2400),

new CargoShip("Black Pearl", "1800", 50000)

};

// Call each object's print function using polymorphism.

for (int index=0; index

{

ships[index]->print();

cout

delete ships[index]; //release memory (avoid memory leak)

ships[index] = nullptr; //avoid dangling pointer

}

system("PAUSE");

return 0;

}

Your solution should consist of six (6) files: Ship.h Ship.cpp CruiseShip.h CruiseShip.cpp CargoShip.h CargoShip.cpp

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!