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

write a c++ program. Define your class in a header file and implement in a .cpp

ID: 3743279 • Letter: W

Question

write a c++ program. Define your class in a header file and implement in a .cpp file also include a main file.

gladiator.h

#ifndef GLADIATOR_H
#define GLADIATOR_H
#include <iostream>
#include <string>
using namespace std;

class gladiator
{
public:
    //constructor and destructor
    gladiator();
    virtual ~gladiator();

    //generate random number by using seedR property
    void setRandomSeed();

    //getters for gladiator properties
    int getSeedR() const;
    int getHP() const;
    double getAS() const;
    double getDS() const;
    int getAppeal() const;
    int getDamage() const;

    //setters for gladiator properties
    void setSeedR(int s);
    void setHP(int s);
    void setAS(double s);
    void setDS(double s);
    void setAppeal(int s);
    void setDamage(int s);

    //function to attack other gladiator
    int attack(gladiator & glad);

    //virtual functions implemented by child classes
    virtual string taunt() = 0;
    virtual void print() = 0;
    virtual void defenceBolster() = 0;
    virtual void specialAction() = 0;

private:
    int HP; //gladiator's health
    double AS; //Attack skill probability of attack 0-1 by them
    double DS; // Defense skill probability attack to them 0-1
    int appeal; //represent charisma and crowd applause
    int damage; //physical damage capacity
    int seedR; // value used when generating randoms seed
};

#endif

---------------------------------------------------------------------------------------------------------------------------------------------------------------------

gladiator.cpp

#include "gladiator.h"
#include <iostream>
#include <string>
#include <iomanip>
#include <stdlib.h>
#include <map>
using namespace std;

//constructor implementation
gladiator::gladiator()
{

}

//destructor
gladiator::~gladiator()
{

}

//generating random seed value
void gladiator::setRandomSeed()
{
    srand(seedR);
}

//getter for seedR
int gladiator::getSeedR() const
{
    return seedR;
}

//getter for HP
int gladiator::getHP() const
{
    return HP;
}

//getter for AS
double gladiator::getAS() const
{
    return AS;
}

//getter for DS
double gladiator::getDS() const
{
    return DS;
}

//getter for Appeal
int gladiator::getAppeal() const
{
    return appeal;
}

//getter for Damage
int gladiator::getDamage() const
{
    return damage;
}

//setter for SeedR
void gladiator::setSeedR(int s)
{
    seedR = s;
}

//setter for HP
void gladiator::setHP(int s)
{
    HP = s;
}

//setter for As
void gladiator::setAS(double s)
{
    AS = s;
}

//setter for Ds
void gladiator::setDS(double s)
{
    DS = s;
}

//setter for appeal
void gladiator::setAppeal(int s)
{
    appeal = s;
}

//setter for damage
void gladiator::setDamage(int s)
{
    damage = s;
}

//implementation of attack
int gladiator::attack(gladiator& glad)
{
   int renown = 0;
   double random = 0 + (1-0)*rand()/((double) RAND_MAX);
   if(random < AS)
   {
       renown += 10;
       double random_2 = 0 + (1-0)*rand()/((double) RAND_MAX);
       if (!(random_2 <= glad.getDS()))
       {
           glad.setHP(glad.getHP()-damage);
           if(glad.getHP() <= 0)
           {
               renown += 30;
           }
       }
   }else
   {
       renown -= 10;
   }
    return appeal+renown; //returning renown + appeal score of attacking glad
}

string gladiator::taunt()
{

}

void gladiator::print()
{

}

void gladiator::defenceBolster()
{

}

void gladiator::specialAction()
{

}

-----------------------------------------------------------------------------------------------------------------------------------------------

trax.h

#ifndef TRAX_H
#define TRAX_H
#include "gladiator.h"
#include <iostream>
#include <string>
using namespace std;

class trax:public gladiator
{
   int sprints;
   public:
   int getSprints();
   void setSprints(int a);
   trax();
   ~trax();
   void print();
   string taunt();
   void defenceBolster();
   void specialAction();
};

#endif

-----------------------------------------------------------------------------------------------------------------------------------

murmillo.h

#ifndef MURMILLO_H
#define MURMILLO_H
#include "gladiator.h"
#include <iostream>
#include <string>
using namespace std;

class murmillo:public gladiator
{
   public:
   murmillo();
   ~murmillo();
   string taunt();
   void print();
   void defenceBolster();
   void specialAction();
};

#endif

------------------------------------------------------------------------------------------------------------------------------------------

retiarus.h

#ifndef RETIARIUS_H
#define RETIARIUS_H
#include "gladiator.h"
#include <iostream>
#include <string>
using namespace std;

class retiarius:public gladiator
{
private:
    int control;
public:
   retiarius();
   ~retiarius();
   int getControl();
   void setControl(int);
   string taunt();
   void defenceBolster();
   void specialAction();
   void print();
};

#endif

----------------------------------------------------------------------------------------------------------------------------------

dimachaerus.h

#ifndef DIMACHAERUS_H
#define DIMACHAERUS_H
#include "gladiator.h"
#include <iostream>
#include <string>
using namespace std;

class dimachaerus:public gladiator
{
   public:
   dimachaerus();
   ~dimachaerus();
   string taunt();
   void defenceBolster();
   void specialAction();
   void print();
};

#endif

The team class encapsulates and holds the individual gladiator objects as a collective fighting team. Here is where a number of the operator overloads will be implemented so that creating and managing gladiator teams is an easy process. team -fightingTeam: gladiator -teamSize:int +team ) +team C) +getSize ):int +aetSize(a:int) :void toperatorll (i:int) : gladiator & toperator+(add:int *):team & toperator-(sub:int *):team & +operator):team +friend operator

Explanation / Answer

team.h : ---------------------------->>>>>>>>>>>>>>>>>>


#ifndef TEAM___H
#define TEAM___H
#include "gladiator.h"
#include "trax.h"
#include "murmillo.h"
#include "retiarius.h"
//#include "dimachaerus.h"

class team{
private:
  gladiator **fightingTeam;
  int teamSize;
public:
  team();
  ~team();
  int getSize();
  void setSize(int s);
  gladiator& operator[](int i);
  team& operator+(int *add);
  team& operator-(int *sub);
  team operator--();
  friend ostream& operator<<(ostream& output,const team &t){
   retiarius *rt;
   trax *tt;
   murmillo *mt;
   dimachaerus *dt;
   for(int i = 0;i<t.teamSize;i++){
    output << " gladiator "<<(i+1)<<":";
    tt = dynamic_cast<trax*>(fightingTeam[i]);
    rt = dynamic_cast<retiarius*>(fightingTeam[i]);
    mt = dynamic_cast<murmillo*>(fightingTeam[i]);
    dt = dynamic_cast<dimachaerus*>(fightingTeam[i]);
    if(tt != NULL){
     output << "Trax";
    }else if(dt != NULL){
     output << "Dimachaerus";
    }else if(rt != NULL){
     output << "Retiarius";
    }else if(mt != NULL){
     output << "Murmillo";
    }
   }
  }
};

#endif

team.cpp : -------------------->>>>>>>>>>>>>>

#include "team.h"

team::team(){
teamSize = 0;
fightingTeam = NULL;
}

team::~team(){
if(fightingTeam != NULL){
  for(int i = 0;i<teamSize;i++){
   delete fightingTeam[i];
  }
  delete fightingTeam;
  fightingTeam = NULL;
  teamSize = 0;
}
}

team team::operator--(){
if(fightingTeam == NULL){
  return *this;
}
for(int i = 0;i<teamSize;i++){
  delete fightingTeam[i];
}
delete fightingTeam;
fightingTeam = NULL;
teamSize = 0;
return *this;
}

int team::getSize(){
return teamSize;
}

void team::setSize(int s){
teamSize = s;
}

gladiator& team::operator[](int i){
return *fightingTeam[i];
}

team& team::operator+(int *add){
if(teamSize <= 0){
  return *this;
}
for(int i = 0;i<teamSize;i++){
  if(add[i] == 1){
   fightingTeam[i] = new trax();
  }else if(add[i] == 2){
   fightingTeam[i] = new murmillo();
  }else if(add[i] == 3){
   fightingTeam[i] = new retiarius();
  }else if(add[i] == 4){
   fightingTeam[i] = new dimachaerus();
  }
}
return *this;
}

team& team::operator-(int *sub){
if(teamSize <= 0){
  return *this;
}
for(int i = 0;i<teamSize;i++){
  if(sub[i] == 1){
   trax *t = dynamic_cast<trax*>(fightingTeam[i]);
   if(t != NULL){
    delete fightingTeam[i];
   }
  }else if(sub[i] == 2){
   murmillo *t = dynamic_cast<murmillo*>(fightingTeam[i]);
   if(t != NULL){
    delete fightingTeam[i];
   }
  }else if(sub[i] == 3){
   retiarius *t = dynamic_cast<retiarius*>(fightingTeam[i]);
   if(t != NULL){
    delete fightingTeam[i];
   }
  }else if(sub[i] == 4){
   dimachaerus *t = dynamic_cast<dimachaerus*>(fightingTeam[i]);
   if(t != NULL){
    delete fightingTeam[i];
   }
  }
}
return *this;
}