Write a c++ program. Define your class in a header file and implement in .cpp fi
ID: 3741913 • Letter: W
Question
Write a c++ program. Define your class in a header file and implement in .cpp file
3.1 Gladiator Class Hierarchy Presented hw be a class diagram depicting the nature of the class hierarchy formed between a parent gladiator class and its children, all of the specific gladiator classes mentioned earlier. The gladiators chosen here represent the more popular of the choices The relationship is a strict one to many relationship with each specific class of gladiator being a direet descendent of the gladiator class. This is presented in FigureExplanation / Answer
* i'm only implemented abstrct class of Gladiotor class as u didn't mention further details for child classes..
1) gladioator.h
#ifndef GLADIATOR_H
#define GLADIATOR_H
#include <iostream>
#include <iomanip>
#include <map>
#include <random>
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:
//for generating random number between M and N
double randNum(double M, double N)
{
return M + (rand() / ( RAND_MAX / (N-M) ) ) ;
}
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_H
2) gladiator.cpp
#include "gladiator.h"
//constructor implementation
gladiator::gladiator()
{
cout<<"gladiator created.."<<endl;
}
//destructor
gladiator::~gladiator()
{
cout<<"gladiator destroyed.."<<endl;
}
//generating random seed value
void gladiator::setRandomSeed()
{
}
//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)
{
double random = randNum(0,1); //generating random number between 0-1
int renown=0; //default renown points
//generated random value is attacked glad's Attack skill
if(random < getAS()){ //if random value less than Attack skill of attacking glad
// means our attacking glad initiated attack
renown=renown+10; //adding renown points
}
else //not
renown=renown-10; //reducing renown points
random = randNum(0,1); //again generating random number
//here random number is required defence skill to defend
if(random > glad.getDS()){ // if attacked glad unable to have that amount of skill
glad.setHP(glad.getHP()-getDamage()); //reducing his Health with our attacking glad's damaging capacity
}
if(glad.getHP() < 0) // and if attacked glad died ie.health =0
renown = renown+30; //adding more 30 points to renown
return getAppeal()+renown; //returning renown + appeal score of attacking glad
}
// these are virtual function of this abstract class
//child classes will have actual implementation
string gladiator::taunt()
{
cout << "default : taunt" << endl;
}
void gladiator::print()
{
cout << "Health : " << getHP()<<endl;
cout << "Appeal : " << getAppeal()<<endl;
cout << "Damage Capacity : " << getDamage()<<endl;
}
void gladiator::defenceBolster()
{
cout << "default : bolster" << endl;
}
void gladiator::specialAction()
{
cout << "default : special action" << endl;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.