Completely stumped on how to do this. It is a class project in which we must make witches and wizards battle at rock, paper, scissors. We are given the code for class "sorcerer", and we have to create two classes "witch" and "wizard" that inherit class "sorcerer." In both classes "witch" and "wizard" we have to implement a function that receives a sorcerer object that is passed by reference.
class sorcerer is as follows
Code:#ifndef _SORCERER_H_ #define _SORCERER_H_ #include <string> using namespace std; class sorcerer { public: sorcerer(); sorcerer(string initName, double initStrength); string getName(); double getStrength(); void takeStrength(sorcerer & s); private: double strength; string name; }; #endif
class wizard is as followsCode:#include "sorcerer.h" sorcerer::sorcerer() { name = ""; strength = 0.0; } sorcerer::sorcerer(string initName, double initStrength) { name = initName; if (initStrength > 0) strength = initStrength; else strength = .1; } string sorcerer::getName() { return name; } double sorcerer::getStrength() { return strength; } void sorcerer::takeStrength(sorcerer & s) { s.strength /= 2; strength += s.strength; }
Code:#ifndef _WIZARD_H_ #define _WIZARD_H_ #include "sorcerer.h" class wizard : public sorcerer { public: wizard(); wizard(string initName, double initStrength, int initMull); int getMull(); private: int mulligan; }; #endifBasically I need to know how to write a function called "fight" in class wizard that will receive a sorcerer object by reference and have them battle at rock, paper scissors. Any help would be greatly appreciatedCode:#include "wizard.h" wizard:: wizard() : sorcerer() { mulligan = 0; } wizard:: wizard(string initName, doubleinitStrength, int initMull) : sorcerer(initName, initStrength) { if (initMull > 0 && initMull < 5) mulligan = initMull; else mulligan = 0; } int wizard::getMull() { return mulligan; }



LinkBack URL
About LinkBacks



