Problem

This Programming Project requires that you first complete Programming Project 14.9 from Ch...

This Programming Project requires that you first complete Programming Project 14.9 from Chapter 14.

Here is an implementation of the getSpecies() function:

The getDamage() function outputs and returns the damage this creature can inflict in one round of combat. The rules for calculating the damage are as follows:

■ Every creature inflicts damage that is a random number r, where 0strength.

■ Demons have a 5% chance of inflicting a demonic attack, which is an additional 50 damage points. Balrogs and Cyberdemons are demons.

■ Elves have a 10% chance to inflict a magical attack that doubles the normal amount of damage.

■ Balrogs are very fast, so they get to attack twice.

An implementation of getDamage() is given here:

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 object. The total damage is then calculated by combining the results of getDamage() at each level of the inheritance hierarchy. As an example, invoking getDamage() for a Balrog object should invoke getDamage() for the Demon object, which should invoke getDamage() for the Creature object. This will compute the basic damage that all creatures inflict, followed by the random 5% damage that demons inflict, followed by the double damage that balrogs inflict.

Also include mutator and accessor functions for the private variables. Write a main function that contains a driver to test your classes. It should create an object for each type of creature and repeatedly outputs the results of getDamage(). First, make the getDamage() function virtual. Then, make a function in your main program, battleArena(Creature &creature1, Creature &creature2), that takes two Creature objects as input. The function should calculate the damage done by creature1, subtract that amount from creature2’s hit points, and vice versa. If both creatures end up with zero or less hit points, then the battle is a tie. Otherwise, at the end of a round, if one creature has positive hit points but the other does not, then the battle is over. The function should loop until the battle is either a tie or over. Since the getDamage() function is virtual, it should invoke the getDamage() function defined for the specific creature. Test your program with several battles involving different creatures.

Step-by-Step Solution

Request Professional Solution

Request Solution!

We need at least 10 more requests to produce the solution.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
Solutions For Problems in Chapter 15