Currently, I do not understand how to implement a function for my Weapon class to reload.
What my program should do (for training purposes) has the Weapon abstract class, which has two classes stemming from it: Sword and Crossbow. The Sword class works as intended, and therefore needs to play. However, the Crossbow class must determine if it is loaded or not, and if it is not loaded, it will load it and run it.
For example, here is a demo output that my teacher gave the class: (this is how it should look)
The crossbow deals 15 damage.
The sword deals 10 damage.
The crossbow is not loaded!
The crossbow deals 15 damage.
Optimistic, I would like it to look similar.
Please, no direct answers. This is homework, and I would really like to know. I am looking for points in the right direction.
Weapon.h
#include <iostream> using namespace std; class Weapon { public: Weapon(int damage = 0); virtual void Attack() const = 0; protected: int m_Damage; }; Weapon::Weapon(int damage) : m_Damage(damage) {} class Sword : public Weapon { public: Sword(int damage = 10); virtual void Attack() const; }; Sword::Sword(int damage): Weapon(damage) {} void Sword::Attack() const { cout << "The sword hits for " << m_Damage << " points of damage" << endl; } class Crossbow : public Weapon { public: Crossbow(int damage = 20); virtual void Attack() const; void Reload() const; }; Crossbow::Crossbow(int damage) : Weapon(damage) {} void Crossbow::Attack() const { cout << "The crossbow hits for " << m_Damage << " points of damage" << endl; } void Crossbow::Reload() const { cout << "Crossbow not loaded! Please reload" << endl; }
source share