i need help creating a header file for each of the following classes. I would be
ID: 3730285 • Letter: I
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 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()<<endl; //print species name before calling getdamage of demon
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";
}
};
Explanation / Answer
//header file for creature
creature.h
class Creature
{
public:
int damage;
int hitPoints;
virtual void getDamage();
virtual string getSpecies()=0;
};
//c++ file for creature
creature.cpp
virtual void Creature::getDamage()
{
cout << "The " << getSpecies() << " attacks for " << damage << " points!" << endl;
}
****************************************
//header file for demon
demon.h
//class demon
class Demon : public Creature
{
public:
string getSpecies();
};
//c++ file for demon
demon.cpp
string Demon:: getSpecies()
{
return "Demon";
}
********************************************
//header file for balrog
balrog.h
//class Balrog
class Balrog : public Demon
{
public:
Balrog(int dam,int x);
void getDamage();
string getSpecies();
};
//c++ file for Balrog
balrog.cpp
Balrog:: Balrog(int dam,int x)
{
damage=dam;
hitPoints=x;
}
void Balrog::getDamage()
{
cout<<"Species name - "+getSpecies()<<endl; //print species name before calling getdamage of demon
Demon::getDamage();//call the getdamage of demon
}
string Balrog::getSpecies()
{
return "Balrog";
}
*******************************************
//header file for cyberdemon
cyberdemon.h
//class Cyberdemon
class Cyberdemon : public Demon
{
public:
Cyberdemon(int dam,int x);
void getDamage();
string getSpecies();
};
//cpp file for cyberdemon
cyberdemon.cpp
Cyberdemon::Cyberdemon(int dam,int x)
{
damage=dam;
hitPoints=x;
};
void Cyberdemon::getDamage()
{
cout << "Species name - "+getSpecies() << endl;//print species name before calling getdamage of demon
Demon::getDamage();
}
string Cyberdemon::getSpecies()
{
return "Cyberdemon";
}
**************************************************************
//header file for human
human.h
//class Human
class Human : public Creature
{
public:
Human(int dam,int x);
string getSpecies();
};
//cpp file for human
human.cpp
Human::Human(int dam,int x)
{
damage=dam;
hitPoints=x;
}
string Human::getSpecies()
{
return "Human";
}
**********************************************
//header file for elf
elf.h
//class Elf
class Elf : public Creature
{
public:
Elf(int dam,int x);
string getSpecies();
};
//cpp file for elf
elf.cpp
Elf::Elf(int dam,int x)
{
damage=dam;
hitPoints=x;
};
string Elf::getSpecies()
{
return "Elf";
}
//i have given all header fille and cpp files for all given classes. for any clarification, please do comments
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.