Question
i need help creating a header file for each of the following classes. I would be glad if i get an answer asap //create class
i need help creating a header file for each of the following classes. I would be glad if i get an answer asap
//create class creature
class Creature
{
public:
int damage;
int hitPoints;
//virtual function so that it calls the right function after derive
virtual void getDamage()
{
cout << "The " << getSpecies() << " attacks for " << damage << " points!" << endl;
}
virtual string getSpecies()=0; //pure virtual function(must be overridden by derived class)
};
//**********************************************************************
//class demon
class Demon : public Creature
{
public:
string getSpecies()
{
return "Demon";
}
};
//***********************************************************************
//class Balrog
class Balrog : public Demon
{
public:
Balrog(int dam,int x)
{
damage=dam;
hitPoints=x;
}
void getDamage()
{
cout<<"Species name - "+getSpecies()< Demon::getDamage();//call the getdamage of demon } string getSpecies() { return "Balrog"; } }; //********************************************************************** //class Cyberdemon class Cyberdemon : public Demon { public: Cyberdemon(int dam,int x) { damage=dam; hitPoints=x; }; void getDamage() { cout << "Species name - "+getSpecies() << endl;//print species name before calling getdamage of demon Demon::getDamage(); } string getSpecies() { return "Cyberdemon"; } }; //********************************************************************** //class Human class Human : public Creature { public: Human(int dam,int x) { damage=dam; hitPoints=x; }; string getSpecies() { return "Human"; } }; //************************************************************************ //class Elf class Elf : public Creature { public: Elf(int dam,int x) { damage=dam; hitPoints=x; }; string getSpecies() { return "Elf"; } };
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started