Here is the correct output. Your output should match this exactly except where random numbers are used. default human strength/hitpoints: 10/10 default elf strength/hitpoints: 10/10 default cyberdemon strength/hitpoints: 10/10 default balrog strength/hitpoints: 10/10 non-default human strength/hitpoints: 20/30 non-default elf strength/hitpoints: 40/50 non-default cyberdemon strength/hitpoints: 60/70 non-default balrog strength/hitpoints: 80/90 Examples of human damage: The human attacks for 8 points! Total damage = 8 The human attacks for 13 points! Total damage = 13 The human attacks for 1 points! Total damage = 1 The human attacks for 14 points! Total damage = 14 The human attacks for 10 points! Total damage = 10 The human attacks for 1 points! Total damage = 1 The human attacks for 18 points! Total damage = 18 The human attacks for 12 points! Total damage = 12 The human attacks for 20 points! Total damage = 20 The human attacks for 8 points! Total damage = 8 Examples of elf damage: The elf attacks for 22 points! Total damage = 22 The elf attacks for 32 points! Total damage 32 The elf attacks for 38 points! Magical attack inflicts 38 additional damage points! Total damage = 76 The elf attacks for 11 points! Magical attack inflicts 11 additional damage points! Total damage = 22 The elf attacks for 16 points! Total damage = 16 The elf attacks for 27 points! Total damage = 27 The elf attacks for 22 points! Magical attack inflicts 22 additional damage points! Total damage = 44 The elf attacks for 38 points! Total damage = 38 The elf attacks for 1 points! Magical attack inflicts 1 additional damage points! Total damage = 2 The elf attacks for 5 points! Magical attack inflicts 5 additional damage points! Total damage = 10 Examples of cyberdemon damage: The cyberdemon attacks for 30 points! Total damage = 30 The cyberdemon attacks for 36 points! Total damage = 36 The cyberdemon attacks for 37 points! Demonic attack inflicts 50 additional damage points! Total damage = 87 The cyberdemon attacks for 7 points! Total damage = 7 The cyberdemon attacks for 10 points! Total damage = 10 The cyberdemon attacks for 14 points! Total damage = 14 The cyberdemon attacks for 6 points! Total damage = 6 The cyberdemon attacks for 25 points! Total damage = 25 The cyberdemon attacks for 16 points! Total damage = 16 The cyberdemon attacks for 13 points! Total damage = 13 Examples of balrog damage: The balrog attacks for 14 points! Demonic attack inflicts 50 additional damage points! balrog speed attack inflicts 77 additional damage points! Total damage = 141 The balrog attacks for 57 points! balrog speed attack inflicts 67 additional damage points! Total damage = 124 The balrog attacks for 27 points! balrog speed attack inflicts 19 additional damage points! Total damage = 46 The balrog attacks for 23 points! balrog speed attack inflicts 64 additional damage points! Total damage = 87 The balrog attacks for 64 points! balrog speed attack inflicts 12 additional damage points! Total damage = 76 The balrog attacks for 70 points! balrog speed attack inflicts 33 additional damage points! Total damage = 103 The balrog attacks for 17 points! balrog speed attack inflicts 69 additional damage points! Total damage = 86 The balrog attacks for 79 points! balrog speed attack inflicts 57 additional damage points! Total damage = 136 The balrog attacks for 54 points! balrog speed attack inflicts 6 additional damage points! Total damage = 60 The balrog attacks for 66 points! Demonic attack inflicts 50 additional damage points! balrog speed attack inflicts 74 additional damage points! Total damage = 190

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter7: Characters, Strings, And The Stringbuilder
Section: Chapter Questions
Problem 1CP
Question

Provide Full C++ Code Solutions for: Creature.h, Creature.cpp, Human.cpp. Human.h, Elf.h, Elf.cpp, Demon.h, Demon.cpp, Cyberdemon.h, Cyberdemon.cpp, Balrog.h, Balrog.cpp

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:

class Creature {

    private:

        int type;               // 0 Human, 1 Cyberdemon, 2 Balrog, 3 elf

        int strength;           // how much damage this Creature inflicts

        int hitpoints;          // how much damage this Creature can sustain

        string getSpecies() const;    // returns the type of the species

    public:

        Creature();             // initialize to Human, 10 strength, 10 hitpoints

        Creature(int newType, int newStrength, int newHitpoints);

        int getDamage() const;         // returns the amount of damage this Creature

                                 // inflicts in one round of combat

        

        // also include appropriate accessors and mutators    

};

 

Here is an implementation of the getSpecies() function:

string Creature::getSpecies() const {

    switch (type) {

        case 0: return "Human";

        case 1: return "Cyberdemon";

        case 2: return "Balrog";

        case 3: return "Elf";

    }

    return "unknown";

}



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:

  • Every Creature inflicts damage that is a random number r, where 0 < r <= strength.
  • Demons have a 25% chance of inflicting a demonic attack which is an additional 50 damage points. Balrogs and Cyberdemons are Demons.
  • With a 50% chance elves 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 below:

int Creature::getDamage() const {

    int damage;

    

    // All Creatures inflict damage which is a random number up to their strength

    damage = (rand() % strength) + 1;

    cout << getSpecies() << " attacks for " << damage << " points!" << endl;

    

    // Demons can inflict damage of 50 with a 25% chance

    if (type == 2 || type == 1){

        if (rand() % 4 == 0) {

            damage = damage + 50;

            cout << "Demonic attack inflicts 50 additional damage points!" << endl;

        }

    }

    

    // Elves inflict double magical damage with a 50% chance

    if (type == 3) {

        if ((rand() % 2) == 0) {

            cout << "Magical attack inflicts " << damage << " additional damage points!" << endl;

            damage *= 2;

        }

    }

    

    // Balrogs are so fast they get to attack twice

    if (type == 2) {

        int damage2 = (rand() % strength) + 1;

        cout << "Balrog speed attack inflicts " << damage2 << " additional damage points!" << endl;

        damage += damage2;

    }

    

    return damage;

}

 

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.

Output is included in Screenshots below

Here is the correct output. Your output should match this exactly except where random numbers are used.
default human strength/hitpoints: 10/10
default elf strength/hitpoints: 10/10
default cyberdemon strength/hitpoints: 10/10
default balrog strength/hitpoints: 10/10
non-default human strength/hitpoints: 20/30
non-default elf strength/hitpoints: 40/50
non-default cyberdemon strength/hitpoints: 60/70
non-default balrog strength/hitpoints: 80/90
Examples of human damage:
The human attacks for 8 points!
Total damage = 8
The human attacks for 13 points!
Total damage = 13
The human attacks for 1 points!
Total damage = 1
The human attacks for 14 points!
Total damage = 14
The human attacks for 10 points!
Total damage = 10
The human attacks for 1 points!
Total damage = 1
The human attacks for 18 points!
Total damage = 18
The human attacks for 12 points!
Total damage = 12
The human attacks for 20 points!
Total damage = 20
The human attacks for 8 points!
Total damage = 8
Examples of elf damage:
The elf attacks for 22 points!
Total damage = 22
The elf attacks for 32 points!
Total damage 32
The elf attacks for 38 points!
Magical attack inflicts 38 additional damage points!
Total damage = 76
The elf attacks for 11 points!
Magical attack inflicts 11 additional damage points!
Total damage = 22
The elf attacks for 16 points!
Total damage = 16
The elf attacks for 27 points!
Total damage = 27
The elf attacks for 22 points!
Magical attack inflicts 22 additional damage points!
Total damage = 44
The elf attacks for 38 points!
Total damage = 38
The elf attacks for 1 points!
Magical attack inflicts 1 additional damage points!
Total damage = 2
The elf attacks for 5 points!
Magical attack inflicts 5 additional damage points!
Total damage = 10
Examples of cyberdemon damage:
The cyberdemon attacks for 30 points!
Total damage = 30
The cyberdemon attacks for 36 points!
Total damage = 36
The cyberdemon attacks for 37 points!
Demonic attack inflicts 50 additional damage points!
Total damage = 87
The cyberdemon attacks for 7 points!
Total damage = 7
The cyberdemon attacks for 10 points!
Total damage = 10
The cyberdemon attacks for 14 points!
Total damage = 14
The cyberdemon attacks for 6 points!
Total damage = 6
The cyberdemon attacks for 25 points!
Total damage = 25
The cyberdemon attacks for 16 points!
Total damage = 16
Transcribed Image Text:Here is the correct output. Your output should match this exactly except where random numbers are used. default human strength/hitpoints: 10/10 default elf strength/hitpoints: 10/10 default cyberdemon strength/hitpoints: 10/10 default balrog strength/hitpoints: 10/10 non-default human strength/hitpoints: 20/30 non-default elf strength/hitpoints: 40/50 non-default cyberdemon strength/hitpoints: 60/70 non-default balrog strength/hitpoints: 80/90 Examples of human damage: The human attacks for 8 points! Total damage = 8 The human attacks for 13 points! Total damage = 13 The human attacks for 1 points! Total damage = 1 The human attacks for 14 points! Total damage = 14 The human attacks for 10 points! Total damage = 10 The human attacks for 1 points! Total damage = 1 The human attacks for 18 points! Total damage = 18 The human attacks for 12 points! Total damage = 12 The human attacks for 20 points! Total damage = 20 The human attacks for 8 points! Total damage = 8 Examples of elf damage: The elf attacks for 22 points! Total damage = 22 The elf attacks for 32 points! Total damage 32 The elf attacks for 38 points! Magical attack inflicts 38 additional damage points! Total damage = 76 The elf attacks for 11 points! Magical attack inflicts 11 additional damage points! Total damage = 22 The elf attacks for 16 points! Total damage = 16 The elf attacks for 27 points! Total damage = 27 The elf attacks for 22 points! Magical attack inflicts 22 additional damage points! Total damage = 44 The elf attacks for 38 points! Total damage = 38 The elf attacks for 1 points! Magical attack inflicts 1 additional damage points! Total damage = 2 The elf attacks for 5 points! Magical attack inflicts 5 additional damage points! Total damage = 10 Examples of cyberdemon damage: The cyberdemon attacks for 30 points! Total damage = 30 The cyberdemon attacks for 36 points! Total damage = 36 The cyberdemon attacks for 37 points! Demonic attack inflicts 50 additional damage points! Total damage = 87 The cyberdemon attacks for 7 points! Total damage = 7 The cyberdemon attacks for 10 points! Total damage = 10 The cyberdemon attacks for 14 points! Total damage = 14 The cyberdemon attacks for 6 points! Total damage = 6 The cyberdemon attacks for 25 points! Total damage = 25 The cyberdemon attacks for 16 points! Total damage = 16
The cyberdemon attacks for 13 points!
Total damage = 13
Examples of balrog damage:
The balrog attacks for 14 points!
Demonic attack inflicts 50 additional damage points!
balrog speed attack inflicts 77 additional damage points!
Total damage = 141
The balrog attacks for 57 points!
balrog speed attack inflicts 67 additional damage points!
Total damage = 124
The balrog attacks for 27 points!
balrog speed attack inflicts 19 additional damage points!
Total damage = 46
The balrog attacks for 23 points!
balrog speed attack inflicts 64 additional damage points!
Total damage = 87
The balrog attacks for 64 points!
balrog speed attack inflicts 12 additional damage points!
Total damage = 76
The balrog attacks for 70 points!
balrog speed attack inflicts 33 additional damage points!
Total damage = 103
The balrog attacks for 17 points!
balrog speed attack inflicts 69 additional damage points!
Total damage = 86
The balrog attacks for 79 points!
balrog speed attack inflicts 57 additional damage points!
Total damage = 136
The balrog attacks for 54 points!
balrog speed attack inflicts 6 additional damage points!
Total damage = 60
The balrog attacks for 66 points!
Demonic attack inflicts 50 additional damage points!
balrog speed attack inflicts 74 additional damage points!
Total damage = 190
Transcribed Image Text:The cyberdemon attacks for 13 points! Total damage = 13 Examples of balrog damage: The balrog attacks for 14 points! Demonic attack inflicts 50 additional damage points! balrog speed attack inflicts 77 additional damage points! Total damage = 141 The balrog attacks for 57 points! balrog speed attack inflicts 67 additional damage points! Total damage = 124 The balrog attacks for 27 points! balrog speed attack inflicts 19 additional damage points! Total damage = 46 The balrog attacks for 23 points! balrog speed attack inflicts 64 additional damage points! Total damage = 87 The balrog attacks for 64 points! balrog speed attack inflicts 12 additional damage points! Total damage = 76 The balrog attacks for 70 points! balrog speed attack inflicts 33 additional damage points! Total damage = 103 The balrog attacks for 17 points! balrog speed attack inflicts 69 additional damage points! Total damage = 86 The balrog attacks for 79 points! balrog speed attack inflicts 57 additional damage points! Total damage = 136 The balrog attacks for 54 points! balrog speed attack inflicts 6 additional damage points! Total damage = 60 The balrog attacks for 66 points! Demonic attack inflicts 50 additional damage points! balrog speed attack inflicts 74 additional damage points! Total damage = 190
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,