Here is a sample output. As you know, you'll have to pay close attention to spacing, etc., in order to get your program to pass the zyBooks tests. ***** Battle between the balrog and the elf!! ****** The balrog attacks for 5 points! Balrog speed attack inflicts 4 additional damage points! The elf attacks for 23 points! The balrog has 27 hitpoints. The elf has 41 hitpoints. The balrog attacks for 8 points! Demonic attack inflicts 50 additional damage points! Balrog speed attack inflicts 1 additional damage points! The elf attacks for 21 points! The balrog has 6 hitpoints. The elf has -18 hitpoints. The balrog wins! Battle between the balrog and the cyberdemon!! The balrog attacks for 2 points! ****** Balrog speed attack inflicts 3 additional damage points! The cyberdemon attacks for 27 points! The balrog has 23 hitpoints. The cyberdemon has 45 hitpoints. The balrog attacks for 2 points! Balrog speed attack inflicts 10 additional damage points! The cyberdemon attacks for 21 points! The balrog has 2 hitpoints. The cyberdemon has 33 hitpoints. The balrog attacks for 9 points! Balrog speed attack inflicts 7 additional damage points! The cyberdemon attacks for 45 points! Demonic attack inflicts 50 additional damage points! The balrog has -93 hitpoints. The cyberdemon has 17 hitpoints. The cyberdemon wins! Battle between the balrog and the human!! The balrog attacks for 1 points! ****** Balrog speed attack inflicts 6 additional damage points! The human attacks for 17 points! The balrog has 33 hitpoints. The human has 43 hitpoints. The balrog attacks for 4 points! Balrog speed attack inflicts 6 additional damage points! The human attacks for 38 points! The balrog has -5 hitpoints. The human has 33 hitpoints. The human wins! ***** Battle between the elf and the cyberdemon!! ****** The elf attacks for 5 points! The cyberdemon attacks for 46 points! The elf has 4 hitpoints. The cyberdemon has 45 hitpoints. The elf attacks for 2 points! The cyberdemon attacks for 6 points! The elf has -2 hitpoints. The cyberdemon has 43 hitpoints. The cyberdemon wins! Battle between the elf and the human!! ****** The elf attacks for 16 points! Magical attack inflicts 16 additional damage points! The human attacks for 34 points! The elf has 16 hitpoints. The human has 18 hitpoints. The elf attacks for 18 points! The human attacks for 100 points! The elf has -84 hitpoints. The human has 0 hitpoints. The battle results in a tie! Battle between the cyberdemon and the human!! ****** The cyberdemon attacks for 50 points! Demonic attack inflicts 50 additional damage points! The human attacks for 45 points! The cyberdemon has 5 hitpoints. The human has -50 hitpoints. The cyberdemon wins! Special zyBooks submission note: To make this work with zyBooks, you will need to comment out the "srand()" line before submitting. 10. All of the classes should still be in the cs_creature namespace It's messy that in the Balrog class's getDamage() function and the Cyberdemon class's getDamage() function we have to write the name of the species before calling the Demon class's getDamage() function. It would be better if the Demon class's getDamage() function could print the name of the species. Taking this a step further, it would be even better if we didn't have to repeat the cout statement "The attacks for ?? points!" in every class's getDamage() function. It would be better if that cout statement could occur just once, in the Creature class's getDamage() function. 1. In the Creature class's getDamage() function, insert the following statement: cout << "The " << getSpecies () << attacks for " << damage << " points!" << endl; 2. Delete (or, if you prefer, comment out) the similar cout statements that appear in the getDamage() function of each of the 5 derived classes. (There will be one such cout statement to delete in each of the 5 getDamage() functions.) 3. Try executing the program. The results won't be quite what we were hoping for. 4. Now make the getSpecies() function in the Creature class a virtual function, and execute the program again. The results will now be correct. 5. We can now simplify our derived classes even further. Two of the five derived classes have getDamage() functions that do nothing more than call their parent class's getDamage() function. Delete these two functions. (Don't forget to delete both the prototype in the class declaration and the definition.) We don't need them, because they can just inherit the getDamage() function from the Creature class. 6. You may have noticed that the Creature class's getSpecies() function never gets called. However, it is absolutely critical that any class that is derived from the Creature class define a getSpecies() function since that function is called from the Creature class's getDamage() function. The best way to implement this is to make the Creature class's getSpecies() function a pure virtual function, so that every class that is derived from the Creature class will be required to implement a getSpecies() function. Make the Creature class's getSpecies() function a pure virtual function. 7. Comment out the getSpecies() function in the Human class and try compiling the program to see what happens. then uncomment it (i.e., return it to it's previous state). 8. Make getDamage() a virtual function. This will be important so that in your "battle()" function (see below) you can say "Creature1.getDamage()" and the damage will automatically be calculated for the correct Creature. Note that the parameters for "battle()" will be of type "Creature" and they will need to be pass-by-reference. (You might try making them pass-by-value to see what happens.) 9. Create a new client program (discard the client program from part 1 of the assignment). Make a function in your client program that is called from main() and has the following prototype: void battle (Creature & Creaturel, Creature & Creature2); (Note, the parameters are pass-by-reference because the Creature class is an abstract class, so objects of type "Creature" cannot be declared.) The function should calculate the damage done by Creature1, subtract that amount from Creature2's hitpoints, and vice versa. (When I say "subtract that amount from Creature2's hitpoints, I mean that the actual hitpoints data member of the Creature2 object will be modified. Also note that this means that both attacks are happening simultaneously; that is, if Creature2 dies because of Creature1's attack, Creature2 still gets a chance to attack back.) At the end of each round, the function should print the total hitpoints remaining for each Creature. If, at the end of a round, both Creatures end up with 0 or fewer hitpoints, then the battle results in a tie. Otherwise, at the end of a round, if one Creature has positive hitpoints but the other does not, the Creature with positive hitpoints is the winner. The function should loop until the battle is over. To start, you may want to use the following very simple main() function to test your battle() function: int main() { } srand(static_cast (time (nullptr))); Elf e(50,50); Balrog b(50,50); battle (e, b); Once your battle() function is working, test it with the given main() below. In this main(), every Creature has a battle with every other Creature. To do this, we first declare four objects, one each of type Elf, Balrog, Human, and Cyberdemon. Then we declare an array of type Creature* with 4 elements, and make each array element point to one of the four objects. (The array elements will need to be pointers-to-Creatures rather than simply Creatures because Creature is an abstract class.) Then we use nested for loops to call battle() with every possible combination of Creatures. Use these constant definitions: const int NUM CREATURES = 4; const int ELF_DEFAULT_STRENGTH = 24; const int BALROG DEFAULT STRENGTH = 10; const int HUMAN_DEFAULT_STRENGTH = 100; const int CYBERDEMON DEFAULT STRENGTH = const int DEFAULT_HITPOINTS = 50; Use this main() function: 50%; int main() { srand(static_cast(time (nullptr))); Elf e(ELF_DEFAULT_STRENGTH, DEFAULT_HITPOINTS); Balrog b(BALROG_DEFAULT_STRENGTH, DEFAULT_HITPOINTS); Human h(HUMAN_DEFAULT_STRENGTH, DEFAULT_HITPOINTS); Cyberdemon c(CYBERDEMON_DEFAULT_STRENGTH, DEFAULT_HITPOINTS); Creature* creatures[] = {&b, &e, &c, &h}; for (int i = 0; i < NUM_CREATURES; i++) { for (int j = i + 1; j < NUM_CREATURES; j++) { battle (*creatures[i], *creatures[j]);

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Provide the full C++ code for: main.cpp, Human.h, Human.cpp, Elf.h, Elf.cpp, Demon.h, Demon.cpp, Cyberdemon.h, Cyberdemon.cpp, Creature.h, Creature.cpp, Balrog.h, Balrog.cpp

Directions are in the provided Screenshots below

Here is a sample output. As you know, you'll have to pay close attention to spacing, etc., in order to get your program to pass the zyBooks tests.
***** Battle between the balrog and the elf!! ******
The balrog attacks for 5 points!
Balrog speed attack inflicts 4 additional damage points!
The elf attacks for 23 points!
The balrog has 27 hitpoints.
The elf has 41 hitpoints.
The balrog attacks for 8 points!
Demonic attack inflicts 50 additional damage points!
Balrog speed attack inflicts 1 additional damage points!
The elf attacks for 21 points!
The balrog has 6 hitpoints.
The elf has -18 hitpoints.
The balrog wins!
Battle between the balrog and the cyberdemon!!
The balrog attacks for 2 points!
******
Balrog speed attack inflicts 3 additional damage points!
The cyberdemon attacks for 27 points!
The balrog has 23 hitpoints.
The cyberdemon has 45 hitpoints.
The balrog attacks for 2 points!
Balrog speed attack inflicts 10 additional damage points!
The cyberdemon attacks for 21 points!
The balrog has 2 hitpoints.
The cyberdemon has 33 hitpoints.
The balrog attacks for 9 points!
Balrog speed attack inflicts 7 additional damage points!
The cyberdemon attacks for 45 points!
Demonic attack inflicts 50 additional damage points!
The balrog has -93 hitpoints.
The cyberdemon has 17 hitpoints.
The cyberdemon wins!
Battle between the balrog and the human!!
The balrog attacks for 1 points!
******
Balrog speed attack inflicts 6 additional damage points!
The human attacks for 17 points!
The balrog has 33 hitpoints.
The human has 43 hitpoints.
The balrog attacks for 4 points!
Balrog speed attack inflicts 6 additional damage points!
The human attacks for 38 points!
The balrog has -5 hitpoints.
The human has 33 hitpoints.
The human wins!
***** Battle between the elf and the cyberdemon!! ******
The elf attacks for 5 points!
The cyberdemon attacks for 46 points!
The elf has 4 hitpoints.
The cyberdemon has 45 hitpoints.
The elf attacks for 2 points!
The cyberdemon attacks for 6 points!
The elf has -2 hitpoints.
The cyberdemon has 43 hitpoints.
The cyberdemon wins!
Battle between the elf and the human!! ******
The elf attacks for 16 points!
Magical attack inflicts 16 additional damage points!
The human attacks for 34 points!
The elf has 16 hitpoints.
The human has 18 hitpoints.
The elf attacks for 18 points!
The human attacks for 100 points!
The elf has -84 hitpoints.
The human has 0 hitpoints.
The battle results in a tie!
Battle between the cyberdemon and the human!! ******
The cyberdemon attacks for 50 points!
Demonic attack inflicts 50 additional damage points!
The human attacks for 45 points!
The cyberdemon has 5 hitpoints.
The human has -50 hitpoints.
The cyberdemon wins!
Special zyBooks submission note: To make this work with zyBooks, you will need to comment out the "srand()" line before submitting.
10. All of the classes should still be in the cs_creature namespace
Transcribed Image Text:Here is a sample output. As you know, you'll have to pay close attention to spacing, etc., in order to get your program to pass the zyBooks tests. ***** Battle between the balrog and the elf!! ****** The balrog attacks for 5 points! Balrog speed attack inflicts 4 additional damage points! The elf attacks for 23 points! The balrog has 27 hitpoints. The elf has 41 hitpoints. The balrog attacks for 8 points! Demonic attack inflicts 50 additional damage points! Balrog speed attack inflicts 1 additional damage points! The elf attacks for 21 points! The balrog has 6 hitpoints. The elf has -18 hitpoints. The balrog wins! Battle between the balrog and the cyberdemon!! The balrog attacks for 2 points! ****** Balrog speed attack inflicts 3 additional damage points! The cyberdemon attacks for 27 points! The balrog has 23 hitpoints. The cyberdemon has 45 hitpoints. The balrog attacks for 2 points! Balrog speed attack inflicts 10 additional damage points! The cyberdemon attacks for 21 points! The balrog has 2 hitpoints. The cyberdemon has 33 hitpoints. The balrog attacks for 9 points! Balrog speed attack inflicts 7 additional damage points! The cyberdemon attacks for 45 points! Demonic attack inflicts 50 additional damage points! The balrog has -93 hitpoints. The cyberdemon has 17 hitpoints. The cyberdemon wins! Battle between the balrog and the human!! The balrog attacks for 1 points! ****** Balrog speed attack inflicts 6 additional damage points! The human attacks for 17 points! The balrog has 33 hitpoints. The human has 43 hitpoints. The balrog attacks for 4 points! Balrog speed attack inflicts 6 additional damage points! The human attacks for 38 points! The balrog has -5 hitpoints. The human has 33 hitpoints. The human wins! ***** Battle between the elf and the cyberdemon!! ****** The elf attacks for 5 points! The cyberdemon attacks for 46 points! The elf has 4 hitpoints. The cyberdemon has 45 hitpoints. The elf attacks for 2 points! The cyberdemon attacks for 6 points! The elf has -2 hitpoints. The cyberdemon has 43 hitpoints. The cyberdemon wins! Battle between the elf and the human!! ****** The elf attacks for 16 points! Magical attack inflicts 16 additional damage points! The human attacks for 34 points! The elf has 16 hitpoints. The human has 18 hitpoints. The elf attacks for 18 points! The human attacks for 100 points! The elf has -84 hitpoints. The human has 0 hitpoints. The battle results in a tie! Battle between the cyberdemon and the human!! ****** The cyberdemon attacks for 50 points! Demonic attack inflicts 50 additional damage points! The human attacks for 45 points! The cyberdemon has 5 hitpoints. The human has -50 hitpoints. The cyberdemon wins! Special zyBooks submission note: To make this work with zyBooks, you will need to comment out the "srand()" line before submitting. 10. All of the classes should still be in the cs_creature namespace
It's messy that in the Balrog class's getDamage() function and the Cyberdemon class's getDamage() function we have to write the name of the species before calling the Demon class's getDamage() function. It would be better if the Demon class's getDamage() function could print the name of the species. Taking this a step further, it would be even
better if we didn't have to repeat the cout statement "The <whatever> attacks for ?? points!" in every class's getDamage() function. It would be better if that cout statement could occur just once, in the Creature class's getDamage() function.
1. In the Creature class's getDamage() function, insert the following statement:
cout << "The " << getSpecies () <<
attacks for " << damage << " points!" << endl;
2. Delete (or, if you prefer, comment out) the similar cout statements that appear in the getDamage() function of each of the 5 derived classes. (There will be one such cout statement to delete in each of the 5 getDamage() functions.)
3. Try executing the program. The results won't be quite what we were hoping for.
4. Now make the getSpecies() function in the Creature class a virtual function, and execute the program again. The results will now be correct.
5. We can now simplify our derived classes even further. Two of the five derived classes have getDamage() functions that do nothing more than call their parent class's getDamage() function. Delete these two functions. (Don't forget to delete both the prototype in the class declaration and the definition.) We don't need them, because they can just
inherit the getDamage() function from the Creature class.
6. You may have noticed that the Creature class's getSpecies() function never gets called. However, it is absolutely critical that any class that is derived from the Creature class define a getSpecies() function since that function is called from the Creature class's getDamage() function. The best way to implement this is to make the Creature class's
getSpecies() function a pure virtual function, so that every class that is derived from the Creature class will be required to implement a getSpecies() function. Make the Creature class's getSpecies() function a pure virtual function.
7. Comment out the getSpecies() function in the Human class and try compiling the program to see what happens. then uncomment it (i.e., return it to it's previous state).
8. Make getDamage() a virtual function. This will be important so that in your "battle()" function (see below) you can say "Creature1.getDamage()" and the damage will automatically be calculated for the correct Creature. Note that the parameters for "battle()" will be of type "Creature" and they will need to be pass-by-reference. (You might try
making them pass-by-value to see what happens.)
9. Create a new client program (discard the client program from part 1 of the assignment). Make a function in your client program that is called from main() and has the following prototype:
void battle (Creature & Creaturel, Creature & Creature2);
(Note, the parameters are pass-by-reference because the Creature class is an abstract class, so objects of type "Creature" cannot be declared.) The function should calculate the damage done by Creature1, subtract that amount from Creature2's hitpoints, and vice versa. (When I say "subtract that amount from Creature2's hitpoints, I mean that
the actual hitpoints data member of the Creature2 object will be modified. Also note that this means that both attacks are happening simultaneously; that is, if Creature2 dies because of Creature1's attack, Creature2 still gets a chance to attack back.) At the end of each round, the function should print the total hitpoints remaining for each
Creature. If, at the end of a round, both Creatures end up with 0 or fewer hitpoints, then the battle results in a tie. Otherwise, at the end of a round, if one Creature has positive hitpoints but the other does not, the Creature with positive hitpoints is the winner. The function should loop until the battle is over.
To start, you may want to use the following very simple main() function to test your battle() function:
int main()
{
}
srand(static_cast<unsigned> (time (nullptr)));
Elf e(50,50);
Balrog b(50,50);
battle (e, b);
Once your battle() function is working, test it with the given main() below. In this main(), every Creature has a battle with every other Creature. To do this, we first declare four objects, one each of type Elf, Balrog, Human, and Cyberdemon. Then we declare an array of type Creature* with 4 elements, and make each array element point to one of
the four objects. (The array elements will need to be pointers-to-Creatures rather than simply Creatures because Creature is an abstract class.) Then we use nested for loops to call battle() with every possible combination of Creatures.
Use these constant definitions:
const int NUM CREATURES = 4;
const int ELF_DEFAULT_STRENGTH = 24;
const int BALROG DEFAULT STRENGTH = 10;
const int HUMAN_DEFAULT_STRENGTH = 100;
const int CYBERDEMON DEFAULT STRENGTH =
const int DEFAULT_HITPOINTS = 50;
Use this main() function:
50%;
int main()
{
srand(static_cast<unsigned>(time (nullptr)));
Elf e(ELF_DEFAULT_STRENGTH, DEFAULT_HITPOINTS);
Balrog b(BALROG_DEFAULT_STRENGTH, DEFAULT_HITPOINTS);
Human h(HUMAN_DEFAULT_STRENGTH, DEFAULT_HITPOINTS);
Cyberdemon c(CYBERDEMON_DEFAULT_STRENGTH, DEFAULT_HITPOINTS);
Creature* creatures[] = {&b, &e, &c, &h};
for (int i = 0; i < NUM_CREATURES; i++) {
for (int j = i + 1; j < NUM_CREATURES; j++) {
battle (*creatures[i], *creatures[j]);
Transcribed Image Text:It's messy that in the Balrog class's getDamage() function and the Cyberdemon class's getDamage() function we have to write the name of the species before calling the Demon class's getDamage() function. It would be better if the Demon class's getDamage() function could print the name of the species. Taking this a step further, it would be even better if we didn't have to repeat the cout statement "The <whatever> attacks for ?? points!" in every class's getDamage() function. It would be better if that cout statement could occur just once, in the Creature class's getDamage() function. 1. In the Creature class's getDamage() function, insert the following statement: cout << "The " << getSpecies () << attacks for " << damage << " points!" << endl; 2. Delete (or, if you prefer, comment out) the similar cout statements that appear in the getDamage() function of each of the 5 derived classes. (There will be one such cout statement to delete in each of the 5 getDamage() functions.) 3. Try executing the program. The results won't be quite what we were hoping for. 4. Now make the getSpecies() function in the Creature class a virtual function, and execute the program again. The results will now be correct. 5. We can now simplify our derived classes even further. Two of the five derived classes have getDamage() functions that do nothing more than call their parent class's getDamage() function. Delete these two functions. (Don't forget to delete both the prototype in the class declaration and the definition.) We don't need them, because they can just inherit the getDamage() function from the Creature class. 6. You may have noticed that the Creature class's getSpecies() function never gets called. However, it is absolutely critical that any class that is derived from the Creature class define a getSpecies() function since that function is called from the Creature class's getDamage() function. The best way to implement this is to make the Creature class's getSpecies() function a pure virtual function, so that every class that is derived from the Creature class will be required to implement a getSpecies() function. Make the Creature class's getSpecies() function a pure virtual function. 7. Comment out the getSpecies() function in the Human class and try compiling the program to see what happens. then uncomment it (i.e., return it to it's previous state). 8. Make getDamage() a virtual function. This will be important so that in your "battle()" function (see below) you can say "Creature1.getDamage()" and the damage will automatically be calculated for the correct Creature. Note that the parameters for "battle()" will be of type "Creature" and they will need to be pass-by-reference. (You might try making them pass-by-value to see what happens.) 9. Create a new client program (discard the client program from part 1 of the assignment). Make a function in your client program that is called from main() and has the following prototype: void battle (Creature & Creaturel, Creature & Creature2); (Note, the parameters are pass-by-reference because the Creature class is an abstract class, so objects of type "Creature" cannot be declared.) The function should calculate the damage done by Creature1, subtract that amount from Creature2's hitpoints, and vice versa. (When I say "subtract that amount from Creature2's hitpoints, I mean that the actual hitpoints data member of the Creature2 object will be modified. Also note that this means that both attacks are happening simultaneously; that is, if Creature2 dies because of Creature1's attack, Creature2 still gets a chance to attack back.) At the end of each round, the function should print the total hitpoints remaining for each Creature. If, at the end of a round, both Creatures end up with 0 or fewer hitpoints, then the battle results in a tie. Otherwise, at the end of a round, if one Creature has positive hitpoints but the other does not, the Creature with positive hitpoints is the winner. The function should loop until the battle is over. To start, you may want to use the following very simple main() function to test your battle() function: int main() { } srand(static_cast<unsigned> (time (nullptr))); Elf e(50,50); Balrog b(50,50); battle (e, b); Once your battle() function is working, test it with the given main() below. In this main(), every Creature has a battle with every other Creature. To do this, we first declare four objects, one each of type Elf, Balrog, Human, and Cyberdemon. Then we declare an array of type Creature* with 4 elements, and make each array element point to one of the four objects. (The array elements will need to be pointers-to-Creatures rather than simply Creatures because Creature is an abstract class.) Then we use nested for loops to call battle() with every possible combination of Creatures. Use these constant definitions: const int NUM CREATURES = 4; const int ELF_DEFAULT_STRENGTH = 24; const int BALROG DEFAULT STRENGTH = 10; const int HUMAN_DEFAULT_STRENGTH = 100; const int CYBERDEMON DEFAULT STRENGTH = const int DEFAULT_HITPOINTS = 50; Use this main() function: 50%; int main() { srand(static_cast<unsigned>(time (nullptr))); Elf e(ELF_DEFAULT_STRENGTH, DEFAULT_HITPOINTS); Balrog b(BALROG_DEFAULT_STRENGTH, DEFAULT_HITPOINTS); Human h(HUMAN_DEFAULT_STRENGTH, DEFAULT_HITPOINTS); Cyberdemon c(CYBERDEMON_DEFAULT_STRENGTH, DEFAULT_HITPOINTS); Creature* creatures[] = {&b, &e, &c, &h}; for (int i = 0; i < NUM_CREATURES; i++) { for (int j = i + 1; j < NUM_CREATURES; j++) { battle (*creatures[i], *creatures[j]);
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
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education