Chapter 14 & 15
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
Six overloaded relational operators that compare 2 ships. Compare based on the year the ship was built.
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.
Use the following code in your main function to test your classes:
// Create an array of Ship pointers, initialized with
// the addresses of some dynamically allocated objects.
const int SIZE = 3;
Ship *ships[SIZE] = { new Ship("Lolipop", 1960),
new CruiseShip("Disney Magic", 1998, 2400),
new CargoShip("Black Pearl", 1800, 50000) };
int firstShip = 0;
int lastShip = 0;
// Call each object's print function and check for newest and oldest.
for (int index=0; index < SIZE; index++)
{
ships[index]->print();
cout << "----------------------------\n";
//Use overloaded relational operators
if(*ships[index] < *ships[firstShip])
firstShip = index;
if(*ships[index] > *ships[lastShip])
lastShip = index;
}
cout<<endl;
cout<<"The oldest ship built was in " << ships[firstShip]->getYearBuilt() << endl;
ships[firstShip]->print();
cout<<"The newest ship built was in " << ships[lastShip]->getYearBuilt() << endl;
ships[lastShip]->print();
//free up the memory
for (int index=0; index < SIZE; index++)
{
delete ships[index];
}
hello......................message me ...............i can get your work done.............i am ready to start immediately...........thnx......Best Regards