Description: Implement Programing Challenges #12 on page 967 of your text. 1. Mu
ID: 3728521 • Letter: D
Question
Description: Implement Programing Challenges #12 on page 967 of your text. 1. Must overload the operator to enter the information for a CruiseShip. 3. Must overload the operator+ to add the more passenger capacity to a CruiseShip, eg. // increase the passenger capacity by 10 cruiseship- cruiseship + 10; 4. Each class must be implemented using the declaration file h) and implementation file (cpp). Ship.h/Ship.cpp, CruiseShip.h/CruiseShip.cpp, and CargoShip.h/CargoShip.cpp 5. ShipTest.cpp is the main program. Required I/O: F. Last's Ship Program I/OExplanation / Answer
//main.cpp
#include "Ship.h"
#include "CargoShip.h"
#include "CruiseShip.h"
#include "Ship.cpp"
#include "CargoShip.cpp"
#include "CruiseShip.cpp"
int main()
{
Ship *ship1 = new Ship();
Ship *ship2 = new Ship("Betty", "1987");
CruiseShip *cruise1 = new CruiseShip();
CruiseShip *cruise2 = new CruiseShip(780);
CruiseShip *cruise3 = new CruiseShip("Enterprise", "2005", 850);
CargoShip *cargo1 = new CargoShip();
CargoShip *cargo2 = new CargoShip(40);
CargoShip *cargo3 = new CargoShip("Sailor", "1984", 20);
ship1->setName("Docking");
ship1->setYear("2001");
cruise1->setName("Rocket");
cruise1->setYear("1999");
cruise1->setMax(560);
cargo1->setName("Express");
cargo1->setYear("1996");
cargo1->setCargo(25);
cout << "First Ship is named " << ship1->getName() << endl
<< "Second Ship was built in " << ship2->getYear() << endl
<< "First Cruise Ship can hold " << cruise1->getMax() << " passengers" << endl
<< "First Cargo Ship can hold " << cargo1->getCargo() << " tons of cargo" << endl;
ship2->print();
cruise3->print();
cargo3->print();
return 0;
}
---------------------------------------------------------------------------------------------------------
//Ship.cpp
#include "Ship.h"
//constructor
Ship::Ship()
{
setName("");
setYear("");
}
Ship::Ship(string n, string y)
{
setName(n);
setYear(y);
}
//accessor
string Ship::getName() const
{
return name;
}
string Ship::getYear() const
{
return year;
}
//mutators
void Ship::setName(string n)
{
name = n;
}
void Ship::setYear(string y)
{
year = y;
}
void Ship::print() const
{
cout << getName() << " was built in " << getYear() << endl;
}
------------------------------------------------------------------------------------------
//Ship.h
#ifndef SHIP_H
#define SHIP_H
#include <string>
#include <iostream>
using std::string;
using std::cout;
using std::endl;
class Ship
{
string name;
string year;
public:
//constructor
Ship();
Ship(string, string);
//accessor
string getName() const;
string getYear() const;
//mutators
void setName(string);
void setYear(string);
virtual void print() const;
};
#endif
----------------------------------------------------------------------------------------
//CargoShip.cpp
#include "Ship.h"
#include "CargoShip.h"
//constructor
CargoShip::CargoShip():Ship()
{
setCargo(0);
}
CargoShip::CargoShip(int c):Ship()
{
setCargo(c);
}
CargoShip::CargoShip(string n, string y, int c):Ship(n, y)
{
setCargo(c);
}
//accessor
int CargoShip::getCargo() const
{
return maxCargo;
}
//mutators
void CargoShip::setCargo(int c)
{
maxCargo = c;
}
void CargoShip::print() const
{
cout << getName() << " has a cargo capacity of " << getCargo() << " tons" << endl;
}
------------------------------------------------------------------------------------------------
//CargoShip.h
#ifndef CARGOSHIP_H
#define CARGOSHIP_H
#include "Ship.h"
class CargoShip : public Ship
{
int maxCargo;
public:
//constructor
CargoShip();
CargoShip(int);
CargoShip(string n, string y, int c);
//accessor
int getCargo() const;
//mutators
void setCargo(int);
virtual void print() const;
};
#endif
-----------------------------------------------------------------------------------------------
//CruiseShip.cpp
#include "Ship.h"
#include "CruiseShip.h"
//constructor
CruiseShip::CruiseShip():Ship()
{
setMax(0);
}
CruiseShip::CruiseShip(int m):Ship()
{
setMax(m);
}
CruiseShip::CruiseShip(string n, string y, int m):Ship(n, y)
{
setMax(m);
}
//accessor
int CruiseShip::getMax() const
{
return maxPassengers;
}
//mutators
void CruiseShip::setMax(int m)
{
maxPassengers = m;
}
void CruiseShip::print() const
{
cout << getName() << " has a maximum capacity of " << getMax() << " passengers" << endl;
}
-----------------------------------------------------------------------------------------
//CruiseShip.h
#ifndef CRUISESHIP_H
#define CRUISESHIP_H
#include "Ship.h"
class CruiseShip : public Ship
{
int maxPassengers;
public:
//constructor
CruiseShip();
CruiseShip(int);
CruiseShip(string n, string y, int m);
//accessor
int getMax() const;
//mutators
void setMax(int);
virtual void print() const;
};
#endif