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 //


![with // the addresses of 3 dynamically allocated objects. Ship *ships[3] =](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66f45f71a4e49_24966f45f712cfb0.jpg)

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
Get step-by-step solutions from verified subject matter experts
