1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
#include <iostream>
#include <string>
using namespace std;
class Ship{
private:
string name;
string built;
public:
Ship(string n, string y){
name =n;
built =y;}
string getname(){return name;}
string getBuilt(){return built;}
virtual void print(){cout <<"Ship name" << getname() << ", Year built:" << getBuilt << endl;}
};
class CargoShip: public Ship{
private:
int tonnage;
public:
CargoShip(string n, string y, int t):
Ship(n,y){tonnage = t;}
virtual void print(){cout <<"Ship name" << getname() << ", Maximum tonnage:" << tonnage << endl;}
};
class CruiseShip: public Ship{
private:
int pass;
public:
CruiseShip(string n, string y, int p):Ship(n,y){pass =p;}
virtual void print(){cout <<"Ship name: " << getname() << ", Maximumum number passengers: " << pass << endl;}
};
int main()
{
Ship*ships[3] = {new Ship("ship","2000"), new CargoShip("cargo", "2010", 2000), new CruiseShip("Cruise ship", "2004", 500)};
for (int i=0; i<3; i++)
{ships[i] -> print();}
return 0;
}
|