-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCoin.cpp
More file actions
85 lines (76 loc) · 2.12 KB
/
Coin.cpp
File metadata and controls
85 lines (76 loc) · 2.12 KB
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
79
80
81
82
83
84
85
#include "Coin.h"
#include <cstdlib>
#include <ctime>
/**********************************************************
* Coin::Coin *
* This is the constructor. It determines the side of the *
* coin that is facing up ("heads" or "tails") randomly. *
* Initializes the sideUp member variable. *
**********************************************************/
Coin::Coin()
{
int x = rand() % 2;
if (x == 0)
{
sideUp = "heads";
}
else
{
sideUp = "tails";
}
}
/**********************************************************
* Coin::Coin(value) *
* This is the constructor. It determines the side of the *
* coin that is facing up ("heads" or "tails") randomly. *
* Initializes the sideUp member variable. *
**********************************************************/
Coin::Coin(int coinValue)
{
value = coinValue;
int x = rand() % 2;
if (x == 0)
{
sideUp = "heads";
}
else
{
sideUp = "tails";
}
}
/**********************************************************
* Coin::toss *
* This function randomly determines the side of the coin *
* that is facing up and sets the sideUp menber variable *
* accordingly. *
**********************************************************/
void Coin::toss()
{
int x = rand() % 2;
if (x == 0)
{
sideUp = "heads";
}
else
{
sideUp = "tails";
}
}
/**********************************************************
* Coin::getSideUp *
* This function reutrns the value in the member variable *
* sideUp. *
**********************************************************/
std::string Coin::getSideUp()
{
return sideUp;
}
/**********************************************************
* Coin::getValue *
* This function reutrns the value in the member variable *
* value. *
**********************************************************/
int Coin::getValue()
{
return value;
}