Question: c++ programming For the same result, Who's design is better ? explain your answer. Tony's code: 1. class Knight { 2 public: 3 int HP:

c++ programming

For the same result, Who's design is better ? explain your answer.

c++ programming For the same result, Who's design is better ? explain

Tony's code: 1. class Knight { 2 public: 3 int HP: 4. int force; 5. int defense; 6. void attack (Ninja ninja); 7. }; 8. 9. class Ninja { 10. public: 11. int HP: 12. int force; 13. int defense; 14. void attack(Knight knight); 15. }; 16. 17. void Knight: :attack (Ninja ninja) { 18. ninja.HP -= this->force - ninja.defense; 19. if (ninja.HP force + 0.5 * ninja.force; 21. } 22. this->HP -= 0.5 * ninja.force - this->defense; 23. } 24. 25. void Ninja::attack(Knight knight) { 26. knight.defense -= 1; 27. knight.HP -- this->force - knight. defense; 28. this->HP -= 0.5 * knight. force - this->defense; 29.) Mary's code: 1. class Soldier { 2. public: 3. int type; // Ninja = 1; Knight = 2; 4. int HP; 5. int force; 6. int defense; 7. void attack(Soldier soldier); 8. }; 9. 10. void Soldier::attack(Soldier soldier) { 11. if (this->type == 1) soldier.defense -= 1; 12. soldier.HP -= this->force - soldier.defense; 13. if (this->type -- 2 && soldier.HP force += 0.5 * soldier.force; } this->HP -= 0.5 * soldier.force - this->defense

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!