In C++, design a class named "Ship" that keeps the following information:
Write a default constructor as well as a constructor that takes all five arguments. Write appropriate accessor and mutator functions for the class.
Next, write a class named "Ferry" that is derived from the "Ship" class. The "Ferry" class should have member variables that hold the following information:
Write a default constructor as well as a constructor that takes all *ten* arguments (five from the Ferry class, and five from the Ship class), making sure to properly pass some of those arguments to the function call for the base class constructor.
Next, write a class named "NavyShip" that is also derived from the "Ship" class. The "NavyShip" class should have member variables holding the following information:
Just as with the "Ferry" class, write a default constructor as well as a constructor that takes all ten arguments, properly passing the necessary arguments to a function call to the base class constructor.
Demonstrate the classes by writing a program that creates two arrays: one of Ferry objects and one of NavyShip objects. Have each array contain just two objects. Use the data shown below, in the output, to populate your object data.
Sample output is below. Meet this minimum level of output formatting, or improve on it (impress me!). This output also gives you the data necessary to load into your various objects:
Information for the Ferry Walla Walla:
> Registry: US
> Homeport: Seattle
> Length: 440
> Displacement: 4860
> Passenger Capacity: 2000
> Car Capacity: 188
> Origin: Edmonds
> Destination: Kingston
> Ticket Price: 35.95
Information for the Ferry Samish:
> Registry: US
> Homeport: Seattle
> Length: 362
> Displacement: 4320
> Passenger Capacity: 1500
> Car Capacity: 144
> Origin: Anacortes
> Destination: Friday Harbor
> Ticket Price: 45.95
Information for the Navy Ship USS John McCain:
> Registry: US
> Homeport: Yokosuka
> Length: 505
> Displacement: 8900
> Type: Destroyer
> Designation: DDG-56
> Crew: 281
> Nuclear: No
> Max Speed: 35
Information for the Navy Ship USS Ronald Reagan:
> Registry: US
> Homeport: Yokosuka
> Length: 1092
> Displacement: 101400
> Type: Aircraft Carrier
> Designation: CVN-76
> Crew: 3532
> Nuclear: Yes
> Max Speed: 40Note: Could you plz go through this code and let me
know if u need any changes in this.Thank You
_________________
#include <iostream>
#include <iomanip>
#include <ctime>
#include <cstdlib>
#include <sstream>
using namespace std;
class Ship
{
private :
string Registry;
string Homeport;
string Name;
int Length;
int Displacement;
public :
Ship(string registry, string homeport, string name,
int length,
int
displacement) {
this->Registry = registry;
this->Homeport = homeport;
this->Name = name;
this->Length = length;
this->Displacement =
displacement;
}
Ship()
{
this->Registry = "US";
this->Homeport =
"Seattle";
this->Name = " Walla
Walla";
this->Length = 440 ;
this->Displacement = 2000;
}
string getRegistry() {
return Registry;
}
void setRegistry(string registry) {
this->Registry = registry;
}
string getHomeport() {
return Homeport;
}
void setHomeport(string homeport) {
this->Homeport = homeport;
}
string getName() {
return Name;
}
void setName(string name) {
this->Name = name;
}
int getLength() {
return Length;
}
void setLength(int length) {
Length = length;
}
int getDisplacement() {
return Displacement;
}
void setDisplacement(int displacement) {
this->Displacement =
displacement;
}
/* toString() method is used to display
* the contents of an object inside it
*/
string toString()
{
stringstream ss;
cout<<Name<<":"<<endl;
cout<< "> Registry:" << Registry <<
endl;
ss << "> Homeport:" << Homeport << endl;
ss << "> Length:" << Length << endl;
ss << "> Displacement:" << Displacement <<
endl;
return ss.str();
}
};
class Ferry:public Ship
{
private :
int passengerCapacity;
int carCapacity;
string origin;
string destination;
double ticketPrice;
public :
Ferry(string registry, string
homeport, string name, int length,
int
displacement, int passengerCapacity, int carCapacity,
string origin,
string destination, double ticketPrice):Ship(registry, homeport,
name, length, displacement) {
this->passengerCapacity =
passengerCapacity;
this->carCapacity =
carCapacity;
this->origin = origin;
this->destination =
destination;
this->ticketPrice =
ticketPrice;
}
int getPassengerCapacity() {
return passengerCapacity;
}
void setPassengerCapacity(int passengerCapacity)
{
this->passengerCapacity =
passengerCapacity;
}
int getCarCapacity() {
return carCapacity;
}
void setCarCapacity(int carCapacity) {
this->carCapacity =
carCapacity;
}
string getOrigin() {
return origin;
}
void setOrigin(string origin) {
this->origin = origin;
}
string getDestination() {
return destination;
}
void setDestination(string destination) {
this->destination =
destination;
}
double getTicketPrice() {
return ticketPrice;
}
void setTicketPrice(double ticketPrice) {
this->ticketPrice =
ticketPrice;
}
/* toString() method is used to display
* the contents of an object inside it
*/
string toString()
{
stringstream ss;
cout<<"Information for the Ferry ";
cout << Ship::toString();
cout<<"> Passenger
capacity:"<<passengerCapacity<<endl;
cout<< "> Car capacity:" << carCapacity <<
endl;
ss << "> Origin:" << origin << endl;
ss << "> Destination:" << destination <<
endl;
ss << "> Ticket price:" << ticketPrice <<
endl;
return ss.str();
}
};
class NavyShip:public Ship
{
private :
string type;
string destination;
int crew;
bool nuclear;
int maxSpeed;
public :
NavyShip(string registry, string
homeport, string name, int length,
int
displacement, string type, string destination, int crew,
bool nuclear,
int maxSpeed):Ship(registry, homeport, name, length, displacement)
{
this->type = type;
this->destination =
destination;
this->crew = crew;
this->nuclear = nuclear;
this->maxSpeed = maxSpeed;
}
string getType() {
return type;
}
void setType(string type) {
this->type = type;
}
string getDestination() {
return destination;
}
void setDestination(string destination) {
this->destination =
destination;
}
int getCrew() {
return crew;
}
void setCrew(int crew) {
this->crew = crew;
}
bool getNuclear() {
return nuclear;
}
void setNuclear(bool nuclear) {
this->nuclear = nuclear;
}
int getMaxSpeed() {
return maxSpeed;
}
void setMaxSpeed(int maxSpeed) {
this->maxSpeed = maxSpeed;
}
/* toString() method is used to display
* the contents of an object inside it
*/
string toString()
{
stringstream ss;
cout<<"Information for the Navy Ship ";
cout << Ship::toString();
cout<<"> Type: "<<type<<endl;
cout<< "> Destination: " << destination<<
endl;
ss << "> Crew: " << crew<< endl;
if(nuclear)
{
ss << "> Nuclear: Yes " << endl;
}
else
{
ss << "> Nuclear: No "
<< endl;
}
ss << "> Max Speed: " << maxSpeed <<
endl;
return ss.str();
}
};
int main()
{
Ferry f1("US","Seattle","Walla
Walla",440,4860,2000,188,"Edmonds","Kingston",35.95);
Ferry
f2("US","Seattle","Samish",362,4320,1500,144,"Anacortes","Friday
Harbor",45.95);
Ferry ferrys[]={f1,f2};
NavyShip ns1("US","Yokosuka","USS John
McCain",505,8900,"Destroyer","DDG-56",281,false,35);
NavyShip ns2("US","Yokosuka","USS Ronald
Reagan",1092,101400,"Aircraft
Carrier","CVN-76",3532,true,40);
NavyShip navyShips[]={ns1,ns2};
for(int i=0;i<2;i++)
{
cout<<ferrys[i].toString()<<endl;
}
for(int i=0;i<2;i++)
{
cout<<navyShips[i].toString()<<endl;
}
return 0;
}
____________________________
Output:

_______________Could you plz rate me well.Thank You
In C++, design a class named "Ship" that keeps the following information: Registry (which country the...
QUESTION 5 (15 Marks) Inheritance and Polymorphism Design a Ship class that has the following members: • A private String data field named name for the name of the ship. • A private String data field named yearBuilt for the year that the ship was built. • A constructor that creates a ship with the specified name and the specified year that the ship was built. • Appropriate getter and setter methods. A toString method that overrides the toString method...
[JAVA] Program: Design a Ship class that the following members: A field for the name of the ship (a string) o A field for the year the the ship was built (a string) o A constructor and appropriate accessors and mutators A toString method that displays the ship's name and the year it was built Design a CruiseShip class that extends the Ship class. The CruiseShip class should have the following members: A field for the maximum number of passengers...
Design a Ship class that has the following class members: A field for the name of the ship A field for the year the ship was built A constructor Appropriate accessors and mutators toString method that displays the ships name and the year it was built Design a CruiseShip class the inherits from the Ship class. Include the following members: A field for the max number of passengers A constructor Appropriate accessors and mutators toString method that overrides the Ship toString method. The method...
Following the example of the Circle class in Section 8.2, design a class named Rectangle to represent a rectangle. The class contains: ■ Two double data fields named width and height that specify the width and height of the rectangle. The default values are 1 for both width and height. ■ A no-arg constructor that creates a default rectangle. ■ A constructor that creates a rectangle with the specified width and height. ■ A method named getArea() that returns the...
C++ Design: Create a UML Class diagram that reflects the software design of your entire program Q3. Create a class called Passenger that represents passengers of an airline company. A passenger is defined by the following information: - Passenger ID (int) - Name (string) - Address (string) - Tel (string) - Date of birth (of type Date from Q2) Provide the following functions: - A constructor that initializes the data members and provides default arguments. - Accessor methods that return...
(Classes and Objects) Design a class named Box. The class should have the following private members: width - A double member variablethat holds the width of the box. length – A double member variable for holding the length of the box. height – A double member variable of type double that holds the height of the box. In addition, provide the following member functions with full (inline) implementation. a) A default constructor that sets all member variables to 0. b)...
Program Challenge 10 Design a Ship class that the following members: · A field for the name of the ship (a string). · A field for the year that the ship was built (a string). · A constructor and appropriate accessors and mutators. · A toString method that displays the ship’s name and the year it was built. Design a CruiseShip class that extends the Ship class. The CruiseShip class should have the following members: · A field for the...
Design a class named BankAccount that contains: 1. A private int data field named accountId for the account. 2. A private double data field named accountBalance for the account (default 0). 3. A private double data field named annualInterestRate that stores the current interest rate (default 0). Assume all accounts have the same interest rate. 4. A private Date data field named dateCreated that stores the date when the account was created. 5. A private int data field named numberOfDeposits...
Using C++, Write a class named Employee that has the following member variables: name. A string that holds the employee's name. idNumber. An int variable that holds the employee's ID number. department. A string that holds the name of the department where the employee works. position. A string that holds the employee's job title. The class should have the following constructors: A constructor that accepts the following values as arguments and assigns them to the appropriate member variables: employee's name,...
C++ 1. Start with a UML diagram of the class definition for the following problem defining a utility class named Month. 2. Write a class named Month. The class should have an integer field named monthNumber that holds the number of the month (January is 1, February is 2, etc.). Also provide the following functions: • A default constructor that sets the monthNumber field to 1. • A constructor that accepts the number of month as an argument and sets...