#include <string>
#include <iostream>
using namespace std;
class Ship
{
protected:
string shipName;
string year;
public:
Ship();
Ship(string, string);
virtual void print();
};
Ship::Ship()
{
shipName = " ";
year = " ";
}
Ship::Ship(string myName, string myYear) // Constructor
{
//strcpy(shipName, myName);
//strcpy(year, myYear);
shipName = myName;
year = myYear;
}
void Ship::print()
{
cout << shipName << endl;
cout << year << endl;
}
class CargoShip : public Ship
{
protected:
int load;
public:
CargoShip();
CargoShip(string, string, int);
virtual void print();
};
CargoShip::CargoShip() : Ship()
{
load = 0;
}
CargoShip::CargoShip(string myName, string myYear, int myLoad) :
Ship(myName, myYear)
{
load = myLoad;
}
void CargoShip::print()
{
cout << shipName << endl;
cout << load << endl;
}
class CruiseShip : public Ship
{
protected:
int passNum;
public:
CruiseShip();
CruiseShip(string, string, int);
virtual void print();
};
CruiseShip::CruiseShip() : Ship()
{
passNum = 0;
}
CruiseShip::CruiseShip(string myName, string myYear, int myNum) :
Ship(myName, myYear)
{
passNum = myNum;
}
void CruiseShip::print()
{
cout << shipName << endl;
cout << passNum << endl;
}
#include <iostream>
#include <string>
using namespace std;
int main()
{
Ship* shipArray[3];
shipArray[0] = new Ship("S.S. Shippy", "1997");
shipArray[1] = new CruiseShip("S.S. La Cruise", "2017", 20);
shipArray[2] = new CargoShip("S.S El Cargo", "1845", 300);
shipArray[0]->print();
shipArray[1]->print();
shipArray[2]->print();
delete shipArray[0];
delete shipArray[1];
delete shipArray[2];
return 0;
}
I2luY2x1ZGUgPHN0cmluZz4KI2luY2x1ZGUgPGlvc3RyZWFtPgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmNsYXNzIFNoaXAKewoJcHJvdGVjdGVkOgoJCXN0cmluZyBzaGlwTmFtZTsKCQlzdHJpbmcgeWVhcjsKCXB1YmxpYzoKCQlTaGlwKCk7CgkJU2hpcChzdHJpbmcsIHN0cmluZyk7CgkJdmlydHVhbCB2b2lkIHByaW50KCk7Cn07CgpTaGlwOjpTaGlwKCkKewoJc2hpcE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