how to recieve a class object in a function?

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#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 



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#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;
}


class wizard is as follows


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#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;
};
#endif 


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#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;
}



Basically 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 appreciated
Passing a custom class object to a function is exactly the same as passing any other object
Topic archived. No new replies allowed.