-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCoin.cpp
More file actions
49 lines (41 loc) · 1.28 KB
/
Coin.cpp
File metadata and controls
49 lines (41 loc) · 1.28 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
#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()
{
srand(time(0));
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;
}