Question: Objective: Use inheritance, virtual functions, and abstract classes to implement a Polymorphic program. Program Description: You will create an abstract class called Monster. You will
Objective:
Use inheritance, virtual functions, and abstract classes to implement a Polymorphic program.
Program Description:
You will create an abstract class called Monster. You will then derive multiple classes from
Monster: Goblin, Troll, Dragon. From Dragon, you will derive two additional classes: Ice Dragon and Fire Dragon. Each monster type will have unique abilities. This lab is more open ended than any of your previous ones. You are being given more freedom how you attack this program. With that in mind, the requirements will be less specific but make sure you are doing everything that is required.
Requirements:
- Classes you must create
1. Monster
- must be an abstract class
- Each monster has
- an attack()
- randomly generate a number between 0 and strength ?for each attack ?(Strength 10 would generate 010)
- add up all the damage done
- return total damage
- a number of attacks
- a number for strength u?sed during attacking
- a string representing the type
- accessor for type
2. Goblin
- inherits from Monster
- type is Goblin
- has 1 attack
- has strength of 30
- when attacking has a 10% chance of doing double damage
3. Troll
- inherits from Monster
- type is Troll
- has 2 attacks
- has strength 60
- when attacking has a 20% of doing 100 damage for each attack
4. Dragon
- inherits from Monster
- type is Dragon
- has 4 attacks
- has strength 100
- After the initial 4 attacks a dragon has a 50% chance of gaining an additional attack
5. IceDragon
- Inherits from Dragon
- has all the attributes of a Dragon
- type is Ice Dragon
- After all attacks are made (including the possible 1 additional) it has a 50% chance of the total damage being doubled
6. FireDragon
- Inherits from Dragon
- has all the attributes of a Dragon
- type is Fire Dragon
- After the initial 4 or 5 attacks are complete, has a 50% chance of attacking all over again (includes a new chance of having an additional attack as all Dragons have)
- Each class must be defined in a header and implementation file named for the class (*.hpp and *.cpp). All filenames must be all lowercase (Ice Dragon > icedragon)
- Each classes attack() ?function must output describing each attack as well as return total damage. See attached example text for good formatting.
- Each header must have include guards
- All numbers need to be integers
- main.cpp (Requirements for main below)
- - This file will demonstrate your monsters attacks
- - Use rand() from
- - Use srand(1234) in main
- - Create an array of 100 Monster pointers
- - Randomly fill the array with objects of each type
- - - Each type of Monster should have the same chance of being generated (20% rand() % 5)
- - - See above examples for ideas of how to do this
- - - Loop through the entire array and call attack()? on each element of the array and output results
- - free dynamic memory
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
