-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMath.cpp
129 lines (114 loc) · 3.04 KB
/
Math.cpp
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#include "Math.h"
using namespace std;
/*
* Chooses a random operation type to display on the rectangles.
*/
int Math::choose_optype(int num_choices)
{
srand(time(NULL));
return rand() % num_choices;
}
/*
* Generates two operations such that both rectangles display addition operations.
*/
int Math::gen_addscore(int ammo)
{
srand(time(NULL));
int score1 = 2 + rand() % 4;
if (ammo == 1)
return score1;
srand(time(NULL));
int score2 = (int)(ammo / 8) + rand() % ((int)((ammo / 2) - (ammo / 8)));
return max(score1, score2);
}
/*
* Generates two operations such that both rectangles display subtraction operations.
*/
int Math::gen_subscore(int ammo, int flag)
{
if (ammo == 1 && flag == 0)
return 0;
if (ammo == 1 && flag == 1)
return 1;
srand(time(NULL));
int score1 = 1 + rand() % 4;
int score2;
srand(time(NULL));
if (flag == 0)
score2 = (int)(ammo / 4) + rand() % ((int)((ammo * 1.2) - (ammo / 4)));
else
score2 = (int)(ammo / 8) + rand() % ((int)((ammo * 0.5) - (ammo / 8)));
return max(score1, score2);
}
/*
* Generates two operations such that one rectangle displays addition operation and the other displays subtraction operation.
*/
int Math::gen_addandsubscore(int ammo, int flag)
{
if (flag == 0)
{
srand(time(NULL));
int score1 = 2 + rand() % 4;
if (ammo == 1)
return score1;
srand(time(NULL));
int score2 = (int)(ammo / 8) + rand() % ((int)((ammo / 2) - (ammo / 8)));
return max(score1, score2);
}
else
{
srand(time(NULL));
int score1 = 1 + rand() % 4;
int score2;
srand(time(NULL));
score2 = (int)(ammo / 3) + rand() % ((int)((ammo * 1.5) - (ammo / 3)));
return max(score1, score2);
}
}
/*
* Generates two operations such that one rectangle displays addition operation and the other displays multiplication operation.
*/
double Math::gen_addandmulscore(int ammo, int flag)
{
if (flag == 0)
{
srand(time(NULL));
int score1 = 2 + rand() % 4;
if (ammo == 1)
return score1;
srand(time(NULL));
int score2 = (int)(ammo / 8) + rand() % ((int)((ammo / 2) - (ammo / 8)));
return (double)max(score1, score2);
}
else
{
srand(time(NULL));
int num = 8 + rand() % 9;
double temp = (double)num;
double score = temp / 8;
return score;
}
}
/*
* Generates two operations such that one rectangle displays subtraction operation and the other displays division operation.
*/
int Math::gen_subanddivscore(int ammo, int flag)
{
if (flag == 0)
{
srand(time(NULL));
int score1 = 1 + rand() % 4;
int score2;
srand(time(NULL));
score2 = (int)(ammo / 4) + rand() % ((int)((ammo * 1.2) - (ammo / 4)));
return max(score1, score2);
}
else
{
if (ammo <= 2)
return 1;
srand(time(NULL));
int score = 2 + rand() % 9;
return score;
}
}