Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hey. Can you help me with this question. The question is this: Design a Ship class that has the following members: A member variable for

Hey. Can you help me with this question. The question is this:

Design a Ship class that has the following members:

  • A member variable for the name of the ship (a string)
  • A member variable for the year that the ship was built (a string)
  • A constructor and appropriate accessors and mutators
  • A virtual print function that displays the ship's name and the year it was built.

Design a CruiseShip class that is derived from the Ship class. The CruiseShip class should have the following members:

  • A member variable for the maximum number of passengers (an int)
  • A constructor and appropriate accessors and mutators
  • A print function that overrides the print function in the base class. The CruiseShip class's print function should display only the ship's name and the maximum number of passengers.

Design a CargoShip class that is derived from the Ship class. The CargoShip class should have the following members:

  • A member variable for the cargo capacity in tonnage (an int).
  • A constructor and appropriate accessors and mutators.
  • A print function that overrides the print function in the base class. The CargoShip class's print function should display only the ship's name and the ship's cargo capacity.

Demonstrate the classes in a program that has an array of Ship pointers. The array elements should be initialized with the addresses of dynamically allocated Ship, CruiseShip, and CargoShip objects. The program should step through the array, calling each object's print function.

I already did the code, but it's giving me errors. This is what my code looks like this:

#include

#include

using namespace std;

classShip

{

private:

stringTitle;

stringWork;

public:

//Constructor

Ship(string t, string w)

{

t = title;

w = work;

}

//Accessors and mutators

string getTitle()

{

return title;

}

string getWork()

{

return work;

}

//Virtual print function

virtual void displayShip(const Ship *)

{

cout<<"Name:"<

cout<<" "<

}

};

classCruiseShip

{

private:

int people;

public:

//Construcor

CruiseShip(string t, string w, int p) : Ship(t,w)

{

people = p;

}

//Virtual print function

virtual void displayCruiseShip(const CruiseShip *)

{

cout<<"Name: "<

cout<<" "<

}

};

classCargoShip

{

private:

int tonnage;

public:

//Constructor

CargoShip(string t, string w, int t) : Ship(t,w)

{

tonnage = t;

}

//Virtual print function

virtual void displayCargoShip(const CargoShip *)

{

cout<<"Name:"<

cout<<" "<

}

};

int main()

{

const int NUM_SHIPS = 3;

Ship *ships[NUM_SHIPS] =

{

new Ship ("FrancescoMorazan", "1922"),

new CruiseShip ("RoyalCaribbean", "6084021"),

new CargoShip ("Altmark", "14000"),

};

//Display output

for (int i=0; i<3; i++)

{

s[i]->printShip();

("pause");

}

return 0;

}

Can you please help me fix these errors, and help me get this code right. Thanks.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Dental Assisting

Authors: Doni Bird, Debbie Robinson

13th Edition

978-0323624855, 0323624855

Students also viewed these Programming questions

Question

WHAT IS DOUBLE ENTRY ACCOUNTING SYSTEM?

Answered: 1 week ago