Suppose you are creating a fantasy role-playing game. In this game we have four different types of Creatures: Humans, Cyberdemons, Balrogs, and elves. 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 Also include mutator and accessor functions for the private variables. Adhere to the following additional requirements: Each of the 6 classes will have exactly 2 constructors. Every class will have a getSpecies() function. We won't be declaring objects of type "Creature" or "Demon", but you should include getSpecies() functions for them anyway, and they should return "Creature" and "Demon", respectively. Make getSpecies() a public member instead of private. Each of the 5 derived classes will have exactly 4 member functions (including constructors) and no data members The Creature class will have 8 member functions (including 2 constructors, 2 accessors, and 2 mutators) and 2 data members. Here is the client program that you must use to test your classes. int main() { srand(static_cast(time(nullptr))); Human h1; Elf e1; Cyberdemon c1; Balrog b1; Human h(20, 30); Elf e(40, 50); Cyberdemon c(60, 70); Balrog b(80, 90); cout << "default Human strength/hitpoints: " << h1.getStrength() << "/" << h1.getHitpoints() << endl; cout << "default Elf strength/hitpoints: " << e1.getStrength() << "/" << e1.getHitpoints() << endl; cout << "default Cyberdemon strength/hitpoints: " << c1.getStrength() << "/" << c1.getHitpoints() << endl; cout << "default Balrog strength/hitpoints: " << b1.getStrength() << "/" << b1.getHitpoints() << endl; cout << "non-default Human strength/hitpoints: " << h.getStrength() << "/" << h.getHitpoints() << endl; cout << "non-default Elf strength/hitpoints: " << e.getStrength() << "/" << e.getHitpoints() << endl; cout << "non-default Cyberdemon strength/hitpoints: " << c.getStrength() << "/" << c.getHitpoints() << endl; cout << "non-default Balrog strength/hitpoints: " << b.getStrength() << "/" << b.getHitpoints() << endl; cout << endl << endl; cout << "Examples of " << h.getSpecies() << " damage: " << endl; for (int i = 0; i < 10; i++){ int damage = h.getDamage(); cout << " Total damage = " << damage << endl; cout << endl; } cout << endl; cout << "Examples of " << e.getSpecies() << " damage: " << endl; for (int i = 0; i < 10; i++){ int damage = e.getDamage(); cout << " Total damage = " << damage << endl; cout << endl; } cout << endl; cout << "Examples of " << c.getSpecies() << " damage: " << endl; for (int i = 0; i < 10; i++){ int damage = c.getDamage(); cout << " Total damage = " << damage << endl; cout << endl; } cout << endl; cout << "Examples of " << b.getSpecies() << " damage: " << endl; for (int i = 0; i < 10; i++){ int damage = b.getDamage(); cout << " Total damage = " << damage << endl; cout << endl; } cout << endl; }
Suppose you are creating a fantasy role-playing game. In this game we have four different types of Creatures: Humans, Cyberdemons, Balrogs, and elves.
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
Also include mutator and accessor functions for the private variables.
Adhere to the following additional requirements:
- Each of the 6 classes will have exactly 2 constructors. Every class will have a getSpecies() function. We won't be declaring objects of type "Creature" or "Demon", but you should include getSpecies() functions for them anyway, and they should return "Creature" and "Demon", respectively. Make getSpecies() a public member instead of private.
- Each of the 5 derived classes will have exactly 4 member functions (including constructors) and no data members
- The Creature class will have 8 member functions (including 2 constructors, 2 accessors, and 2 mutators) and 2 data members.
Here is the client program that you must use to test your classes.
int main() {
srand(static_cast<unsigned>(time(nullptr)));
Human h1;
Elf e1;
Cyberdemon c1;
Balrog b1;
Human h(20, 30);
Elf e(40, 50);
Cyberdemon c(60, 70);
Balrog b(80, 90);
cout << "default Human strength/hitpoints: " << h1.getStrength() << "/" << h1.getHitpoints() << endl;
cout << "default Elf strength/hitpoints: " << e1.getStrength() << "/" << e1.getHitpoints() << endl;
cout << "default Cyberdemon strength/hitpoints: " << c1.getStrength() << "/" << c1.getHitpoints() << endl;
cout << "default Balrog strength/hitpoints: " << b1.getStrength() << "/" << b1.getHitpoints() << endl;
cout << "non-default Human strength/hitpoints: " << h.getStrength() << "/" << h.getHitpoints() << endl;
cout << "non-default Elf strength/hitpoints: " << e.getStrength() << "/" << e.getHitpoints() << endl;
cout << "non-default Cyberdemon strength/hitpoints: " << c.getStrength() << "/" << c.getHitpoints() << endl;
cout << "non-default Balrog strength/hitpoints: " << b.getStrength() << "/" << b.getHitpoints() << endl;
cout << endl << endl;
cout << "Examples of " << h.getSpecies() << " damage: " << endl;
for (int i = 0; i < 10; i++){
int damage = h.getDamage();
cout << " Total damage = " << damage << endl;
cout << endl;
}
cout << endl;
cout << "Examples of " << e.getSpecies() << " damage: " << endl;
for (int i = 0; i < 10; i++){
int damage = e.getDamage();
cout << " Total damage = " << damage << endl;
cout << endl;
}
cout << endl;
cout << "Examples of " << c.getSpecies() << " damage: " << endl;
for (int i = 0; i < 10; i++){
int damage = c.getDamage();
cout << " Total damage = " << damage << endl;
cout << endl;
}
cout << endl;
cout << "Examples of " << b.getSpecies() << " damage: " << endl;
for (int i = 0; i < 10; i++){
int damage = b.getDamage();
cout << " Total damage = " << damage << endl;
cout << endl;
}
cout << endl;
}
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 11 images