Project #28203 - C ++

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]; 

 } 

 

Subject Computer
Due By (Pacific Time) 04/29/2014 05:00 pm
Report DMCA
TutorRating
pallavi

Chat Now!

out of 1971 reviews
More..
amosmm

Chat Now!

out of 766 reviews
More..
PhyzKyd

Chat Now!

out of 1164 reviews
More..
rajdeep77

Chat Now!

out of 721 reviews
More..
sctys

Chat Now!

out of 1600 reviews
More..
sharadgreen

Chat Now!

out of 770 reviews
More..
topnotcher

Chat Now!

out of 766 reviews
More..
XXXIAO

Chat Now!

out of 680 reviews
More..
All Rights Reserved. Copyright by AceMyHW.com - Copyright Policy