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

I need help with writing this program in C++ Monster, Orc, and Eagle Classes Des

ID: 3662873 • Letter: I

Question

I need help with writing this program in C++

Monster, Orc, and Eagle Classes

Design a Monster class that has the following members:

--A member variable for the name of the Monster (a string )
--A member variable for the hit points of the monster (an int )
--A constructor and appropriate accessors and mutators
--A virtual print function that displays the Monster's name and hit points.

Design an Orc class that is derived from the Monster class.

The Orc class should have the following members:
--A member variable for the maximum damage per second the orc can inflict ( a floating point number )
--A constructor and appropriate accessors and mutators
--A print function that overrides the print function in the base class. The Orc class's print function should display only the Orc's name and the damage per second.

Design a Eagle class that is derived from the Ship class.

The Eagle class should have the following members:
--A member variable for the flight speed of the Eagle ( an int ).
--A constructor and appropriate accessors and mutators.
--A print function that overrides the print function in the base class. The Eagle class's print function should display only the Eagle's name and the Eagle's flight speed.

Demonstrate the classes in a program that has an array of Monster pointers. The array elements should be initialized with the addresses of dynamically allocated Monster, Orc, and Eagle objects. (See Program 15-14, lines 17 through 22, for an example of how to do this.) The program should then step through the array, calling each object's print function.

*Be sure to include accessors and mutators for each member variable in each class.

*Don't forget to deallocate all your memory: Monster, Orc, Eagle.

SAMPLE RUN:

Explanation / Answer

#include <iostream>
using namespace std;

class monster
{
   protected:
       string name;   // A member variable for the name of the Monster (a string )
       int hitpoints; // A member variable for the hit points of the monster (an int )

   public:
  
       monster(){ // constractor
      
       }
  
       void setname(string nm){
           name = nm;
       }
      
       string getname(){
           return name;
       }
      
       void sethitpoints(int hitp){
           hitpoints = hitp;
       }
       int gethitpoints(){
           return hitpoints;
       }
       // A virtual print function that displays the Monster's name and hit points
       virtual void print(){
           cout << "Name : "<<getname()<<endl;
           cout << "Hit Points : "<<gethitpoints()<<endl;
       }
       // Virtual Destructor is declared to run derived class destructor
       virtual ~monster(){
           // to test destructor umcomment below line
//           cout<<" monster class destructor for deallocation"<<endl;

       }
};


class orc : public monster{

  
   protected:
       float damageperS; // A member variable for the maximum damage per second the orc can inflict ( a floating point number )
   public:
       orc(){
          
       }
       void setdamageperS(float dps){
           damageperS = dps;  
       }
       float getdamageperS(){
           return damageperS;
       }
       void print(){
           cout << "Name : "<<getname()<<endl;
           cout << "Maximum damage per second : "<<getdamageperS()<<endl;  
       }
       ~orc(){
           // to test destructor umcomment below line
//           cout<<"Drived orc class destructor for deallocation"<<endl;
       }
  
};

class ship :public monster{
   protected:
       string name;
       int year;
   public:
       ship(){
          
       }
       void setname(string nm){
           name = nm;
       }
      
       string getname(){
           return name;
       }
       void setyear(int yr){
           year = yr;
       }
       int getyear(){
           return year;
       }
       virtual void print(){
           cout << "Name : "<<getname()<<endl;
           cout << "Year built: "<<getyear()<<endl;  
                 
       }
       ~ship(){
       }
};

class eagle :public ship{
  
   protected:
  
       int fspeed ;
   public:
       eagle(){
          
       }
      
       void setflightspeed(int fspd){
           fspeed = fspd;
       }
       int getflightspeed(){
           return fspeed;
       }
       void print(){
           cout << "Name : "<<getname()<<endl;
           cout << "Flight speed: "<<getflightspeed()<<endl;  
                 
       }
       ~eagle(){
           // to test destructor umcomment below line
//           cout<<"Drived eagle class destructor for deallocation"<<endl;
       }
};

int main(){

   monster *mons[10]; // array of Monster pointers
  
  
   // dynamically allocating monster objects adress to pointer element
   monster mntobj;      
   mons[0] = &mntobj;  
   mons[0]->setname("Bilbo");
   mons[0]->sethitpoints(10);

  
       // dynamically allocating ORC objects
   orc orcobj;
   orcobj.setname("Smash");
   orcobj.setdamageperS(15.8);
   mons[1] = &orcobj;
  
   // Dynamically allocating Eagle objects
   eagle eagleobj;
   eagleobj.setname("Screech");
   eagleobj.setflightspeed(100);  
   mons[2]= &eagleobj;
  
   // Through the array of pointer, calling each object's print function
  
   for(int i = 0;i<3;i++){
       mons[i]->print();
   }

// running destructor
   orcobj.~orc();
   mntobj.~monster();
   eagleobj.~eagle();
   delete mons;
}