Starting from:

$30

CS2028-Lab 4 Inheritance, Polymorphism and Abstract classes Solved

The objective of this Lab is to examine Inheritance, Polymorphism and Abstract classes.

 

Task 1:  Create a base class that will be used as the basis for the remainder of the lab.

1.     Create a new project.  You can name this whatever you like.

2.     Design a class to abstractly model games.  You may want to read the entire assignment before starting this task.

a.      Include at least 2 attributes along with getters and setters for the attributes.

b.     Create a default constructor and an overload constructor allowing you to set values for all attributes.

c.      Define a virtual function called Play that prints out “Let’s play”.  Define a non-virtual function called Winner that prints out the string “Not Yet”.

d.     Create the implementation code for the above functions as required.

3.     Include in the submission how each member will be available in derived classes (i.e. not available, available if not overridden, etc…).  Complete this before moving on to task 2.

 

Task 2:  Create 2 classes that inherit from this class.

1.     Create a class for board game and video game that inherits from Game.

2.     Board game should have the following features:

a.      Play should be defined as printing out “Role the dice.”

b.     Winner should be defined as printing out “Dancing time.”

c.      Add 1 additional attribute to the board game class.  Include a getter and setter.

3.     Video game should have the following features:

a.      Play should be defined as printing out “Mash the buttons.”

b.     Winner should be defined as printing out “Winner music”

c.      Add 1 additional attribute for the video game class (different from the board game class).  Include a getter and setter.

4.     Include in the submission what version of the derived class members will be available in instances of the derived class and in instances of the derived class declared as the base class type.  Complete this before moving on to task 3.

 

Task 3:  Test the classes.

1.     Create a program that tests the classes.

a.      Prompt the user for which class to create and values to set the attributes for that class.  Include the option to create a board game or video game as a game.  This may look like:

Press 1 for an instance of game.

Press 2 for an instance of board game.

Press 3 for an instance of video game.

Press 4 for an instance of a board game declared as a game

Press 5 for an instance of a video game declared as a game
b.     Call the “Play” and “Winner” functions from the instance created in step a.

c.      Create a function outside of classes that accepts a game as a parameter.  This function should call the Play and Winner functions of the input parameter.

d.     Call the function from step c.

e.      Ask the user if they wish to continue.  If so, loop to step a.

2.     Use your test program to test all member functions and ensure the class is working correctly.

3.     Include in the lab report a screen shot(s) of the output of a test.  Include a discussion of how the actual results compared with the expected results from Task 2.

More products