Page 1 of 1

Note: you may omit documentation on all parts of this assignment. Suppose you are creating a fantasy role-playing game.

Posted: Thu May 05, 2022 12:46 pm
by answerhappygod
Note: you may omit documentation on all parts of this
assignment.
Suppose you are creating a fantasy role-playing game. In this
game we have four different types of Creatures: Humans,
Cyberdemons, Balrogs, and elves. To represent one of these
Creatures we might define a Creature class as follows:
Here is an implementation of the getSpecies() function:
In case you aren't sure what a Balrog is, here is a Balrog
video.
The getDamage() function outputs and returns the damage this
Creature can inflict in one round of combat. The rules for
determining the damage are as follows:
An implementation of getDamage() is given below:
One problem with this implementation is that it is unwieldy to
add new Creatures. Rewrite the class to use inheritance, which will
eliminate the need for the variable "type". The Creature class
should be the base class. The classes Demon, Elf, and Human should
be derived from Creature. The classes Cyberdemon and Balrog should
be derived from Demon. You will need to rewrite the getSpecies()
and getDamage() functions so they are appropriate for each
class.
For example, the getDamage() function in each class should only
compute the damage appropriate for that specific class. The total
damage is then calculated by combining that damage with the results
when getDamage() is called on the class's parent class. As an
example, Balrog inherits from Demon, and Demon inherits from
Creature. So invoking getDamage() for a Balrog object invokes
getDamage() for a Demon object, which should invoke getDamage() for
the Creature object. This will compute the basic damage that all
Creatures inflict, followed by the random 25% damage that Demons
inflict, followed by the double damage that Balrogs inflict.
Also include mutator and accessor functions for the private
variables.
Adhere to the following additional requirements:
Here is the client program that
you must use to test your classes.
Here is the correct output. Your output should match this
exactly except where random numbers are used.