Some simple homework help

In this project, I'm supposed to have a FootballGame class that uses some objects created by a Referee class. I'm not entirely sure how to do this.

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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#pragma once
#include <iostream>
#include "Flag.h"
using namespace std;

class Referee
{
private:
	int totalFlags;
public:
	Referee()
	{
		totalFlags = 0;
	};
	~Referee()
	{

	};
	void watchPlay()
	{
		int random = rand() % 100 + 1;
		if (totalFlags > 2)
		{

//I'm supposed to read these flags that I'm making in this method in my FootballGame class
			if (random <= 20)
			{
				Flag* flag = new Flag("Holding", "Offense",-10);
				totalFlags++;
			}

			if (random > 20 && random <= 40)
			{
				Flag* flag = new Flag("Offsides", "Defense", 5);
				totalFlags++;
			}
		}
		
	};
};


#pragma once
#include <iostream>
#include "Play.h"
#include "Referee.h"
#include "Flag.h"
using namespace std;

class FootballGame
{
private:
	Referee* referee;
public:
	FootballGame();
	int runPlay(Play *play)
	{
		referee->watchPlay();

//Here's where I need the flags to be read, but I'm not sure how I can do it. I was planning on using the if/else statements in some way, but I don't necessarily need to use them.

		if ( )
		{
                //If a flag is created in the Referee Class, I need to read it here. 
                //I have a toString() method in my Flag class that I need to use in order to read it here.
                }

		else
		{
			return 0;
		}
	};
	~FootballGame()
	{
		delete referee;
		//delete Flag*;
	}
};
Last edited on
I figured out that a try/catch block is what I'm supposed to do, rather than a if/else statement. Now I'm just trying to make it try the referee->watchPlay() part and catch the flag. Still having some trouble, but I'm getting closer.
Topic archived. No new replies allowed.