Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Oracle RMAN For Absolute Beginners

Authors: Darl Kuhn

1st Edition

1484207637, 9781484207635

More Books

Students also viewed these Databases questions