Question: Create a Sword class . The Ninja class below HAS a Sword object (composition/aggregation). The Sword class has these instance variables: attack damage and attack

Create a Sword class. The Ninja class below HAS a Sword object (composition/aggregation).

  • The Sword class has these instance variables: attack damage and attack decay, both integers.
  • Sword's constructor should include attack damage and attack decay. The name "Sword" should be hardcoded.
  • The attack method returns an attack value. The Ninja attack skill plus the Sword attack damage is the attack value returned. After each attack, the sword's attack damage decreases by the amount of the attack decay. (The sword becomes weaker and weaker after each use).

Create a Ninja class.

  • Ninja has a sword. That sword object instance variable is a pointer to a sword object. This instance variable has a "protected" access value.
  • Other Ninja class instance variables include: name, health, and attack skill. The latter two are whole numbers.
  • Create a constructor. The constructor should accept a name, health, and attack skill. Set the sword object initially to a nullptr.
  • Create an appropriate copy constructor.
  • Overload the = operator appropriately.
  • The sword object has an attack method (see above for the Sword class definition). The ninja class should also have an attack function. The ninja class' attack function calls the sword's public attack function. This gives outside classes access to the sword's attack function without giving an outside class the ability to overwrite the entire sword object (since sword is a pointer).
  • Create a pickupSword method. This accepts as a parameter a sword object. The sword object that is passed into this function becomes this player's sword.

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!