Vous êtes sur la page 1sur 1

Object Oriented Programming Lab

O b j e c t O r i e n t e d P r o gr a m m i n g L a b
Lab 0 6 Marks 10
Instructions
Work on this lab individually. You can use your books, notes, handouts etc. but you are not allowed to borrow anything from your
peer student.
Marking Criteria
Show your work to the instructor before leaving the lab to get some or full credit.
What you have to do
Program the following tasks in your Microsoft C++ compiler and then compile and execute them. The name of your files will be
according to the task given in this lab.

Ship, CruiseShip, CargoShip and BattleShip Classes

1. Ship class
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(s) and appropriate property methods.
 A virtual print function that displays the ship’s name and the year it was built.

2. CruiseShip class
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(s) and appropriate property methods.
 A print function that overrides the print function in the base class. The CruiseShip class’s print function should
display the ship’s name, year of built and the maximum number of passengers.

3. CargoShip class
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(s) and appropriate property methods.
 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.

4. BattleShip class
Design a BattleShip class that is derived from the Ship class. The BattleShip class should have the following members:
 A member variable for the total number of missiles (an int).
 A constructor(s) and appropriate property methods.
 A print function that overrides the print function in the base class. The BattleShip class’s print function should
display only the ship’s name and the missiles’ capacity.

5. A Driver Program
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, CargoShip and BattleShip objects. The program should then step through
the array, calling each object’s print function.

☺ ☺ ☺ BEST OF LUCK ☺ ☺ ☺

Vous aimerez peut-être aussi