Question: I need my code to have none initialization list #include #include #include using namespace std; class Ship { protected: string name; string yearBuilt; public: Ship
I need my code to have none initialization list #include
#include
#include
using namespace std;
class Ship
protected:
string name;
string yearBuilt;
public:
Shipconst string& name, const string& yearBuilt
: namename yearBuiltyearBuilt
string getName const return name;
string getYearBuilt const return yearBuilt;
virtual void print const
cout "Ship name: name
;
cout "Year built: yearBuilt
;
;
class CruiseShip : public Ship
private:
int maxPassengers;
public:
CruiseShipconst string& name, const string& yearBuilt, int maxPassengers
: Shipname yearBuilt maxPassengersmaxPassengers
int getMaxPassengers const return maxPassengers;
void print const override
cout "Cruise Ship name: getName
;
cout "Maximum passengers: maxPassengers
;
;
class CargoShip : public Ship
private:
int cargoCapacity;
public:
CargoShipconst string& name, const string& yearBuilt, int cargoCapacity
: Shipname yearBuilt cargoCapacitycargoCapacity
int getCargoCapacity const return cargoCapacity;
void print const override
cout "Cargo Ship name: getName
;
cout "Cargo capacity: cargoCapacity tons"
;
;
int main
vector ships;
ships.pushbacknew ShipShip A;
ships.pushbacknew CruiseShipCruise Ship B;
ships.pushbacknew CargoShipCargo Ship C;
for const auto& ship : ships
shipprint;
cout
;
return ;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
