-
Notifications
You must be signed in to change notification settings - Fork 0
/
arithmetic.class.php
71 lines (57 loc) · 1.71 KB
/
arithmetic.class.php
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
<?php
class arithmetic
{
private $db;
private $exam = array();
public $beginTime, $endTime;
function __construct()
{
//-- connect to database
$dbHandle = "./arithmetic.db";
$this->db = new SQLite3($dbHandle);
//-- arithmetic type
}
public function makeExam($ruler)
{
$this->exam = array();
$i = 0;
while ($i < $ruler['amount']) {
$figure = array(
rand($ruler['range_a']['min'], $ruler['range_a']['max']),
rand($ruler['range_b']['min'], $ruler['range_b']['max'])
);
if(array_sum($figure) == 0)
continue;
if($i % 2 == 0)
{
$a = $figure[0];
$b = $figure[1];
$result = array_sum($figure);
if($result > $ruler['max'])
continue;
$sign = ' + ';
}
else
{
$a = max($figure);
$b = min($figure);
$result = $a - $b;
$sign = ' - ';
}
$this->exam[] = array(
'exam' => $a.$sign.$b.' = ',
'rightAnswer' => $result,
'submitTime'=> '',
'result' => ''
);
$i = count($this->exam);
}
shuffle($this->exam);
return $this->exam;
}
function __destruct()
{
$this->db->close();
}
}
?>