Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a class called \"Potion\" Potions are used to heal a character The potion

ID: 3732203 • Letter: C

Question


Create a class called "Potion" Potions are used to heal a character The potion should have 2 private members: count and healingAmount . count holds the number of potions the player has available healingAmount holds the amount of health recovered by the character The potion constructor should allow the programmer to specify how many potions are available o The class should have a member function called "use" the use function should be passed a character pointer or reference for the character being healed the function should invoke the heal member function of the character using the potion when the use function is called, the potion count should drop by 1 - if the count value is O or lower, no healing should be performed The class should have an accesser function called getCount() which returns the number of potions available . The combat code should now prompt the user whether they want to attack the creature or use a potion if the user selects to use a potion, the npc/enemy character should stil attack them o if the playerCharacter is slower than the npc/enemy character, they should be attacked before they get the chance to heal

Explanation / Answer

here is your modified Character class only modified portion + Potion class : =------------->>>>>>>

#include<iostream>

using namespace std;

class Character{
string name;
//other data member same
public:
  void heal(int healAmount){
   //same
  }
  Character(){
   //same
   name = "";
  }
  Character(/*same....*/string name){
   //same
   this->name = name;
  }
  //same function which were there earlier
  void setName(string name){
   this->name = name;
  }
  string getName()const{
   return name;
  }
};

class Potion{
int count;
int healAmount;

public:
  Potion(){
   //give default value here for count and healAmount
   count = 10;
   healAmount = 100;
  }
  Potion(int count,int healAmount){
   this->count = count;
   this->healAmount = healAmount;
  }
  void use(Character &ch){
   ch.heal(healAmount);
   count--;
  }
  int getCount()const{
   return count;
  }
};

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote