Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional Microsoft SQL Server 2014 Administration

Authors: Adam Jorgensen, Bradley Ball

1st Edition

111885926X, 9781118859261

More Books

Students also viewed these Databases questions

Question

Ty e2y Evaluate the integral dy

Answered: 1 week ago