lineaire-vergelijkingen
Gesponsorde koppelingen
PHP script bestanden
Code (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
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
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
<html>
<head>
<title>Lineaire vergelijkingen</title>
</head>
<body>
<?php
error_reporting(E_ALL);
$valueof1 = '';
$valueof2 = '';
$valueof3 = '';
$valueof4 = '';
if(isset($_POST['1'],$_POST['2'],$_POST['3'],$_POST['4'])) {
$_POST['1'] = preg_replace('/^([a-zA-Z]+?)$/','x', $_POST['1']);
$_POST['2'] = preg_replace('/^([a-zA-Z]+?)$/','x', $_POST['2']);
$_POST['3'] = preg_replace('/^([a-zA-Z]+?)$/','x', $_POST['3']);
$_POST['4'] = preg_replace('/^([a-zA-Z]+?)$/','x', $_POST['4']);
$valueof1 = ($_POST['1'] != 'x') ? htmlspecialchars($_POST['1']) : '1x';
$valueof2 = ($_POST['2'] != 'x') ? htmlspecialchars($_POST['2']) : '1x';
$valueof3 = ($_POST['3'] != 'x') ? htmlspecialchars($_POST['3']) : '1x';
$valueof4 = ($_POST['4'] != 'x') ? htmlspecialchars($_POST['4']) : '1x';
$points = 0;
$numbers = array();
$other = array();
if(is_numeric($valueof1)) {
$points += 1;
$numbers[] = $valueof1;
} else {
$points -= 1;
$other[] = ($valueof1 * -1).'x';
}
if(is_numeric($valueof2)) {
$points += 1;
$numbers[] = $valueof2;
} else {
$points -= 1;
$other[] = ($valueof2 * -1).'x';
}
if(is_numeric($valueof3)) {
$points += 1;
$numbers[] = $valueof3 * -1;
} else {
$points -= 1;
$other[] = $valueof3;
}
if(is_numeric($valueof4)) {
$points += 1;
$numbers[] = $valueof4 * -1;
} else {
$points -= 1;
$other[] = $valueof4;
}
if($points == 0) {
$num1 = $numbers[0];
$num2 = $numbers[1];
$num3 = $other[0];
$num4 = $other[1];
$result1 = preg_replace('/\+\+/', '+', $num1+$num2);
$result2 = preg_replace('/\+\+/', '+', $num3+$num4);
$result = $result1/$result2;
$plus1 = (substr($num2, 0, 1) == '-') ? '' : '+';
$plus2 = (substr($num4, 0, 1) == '-') ? '' : '+';
echo "<b>Invoer:</b> ".$valueof1.$valueof2." = ".$valueof3.$valueof4."<br>\n";
echo "<b>Stap 1:</b> ".$num1.$plus1.$num2." = ".$num3.$plus2.$num4."<br>\n";
echo "<b>Stap 2:</b> ".preg_replace('/\+\+/', '+', $num1+$num2)." = ".preg_replace('/\+\+/', '+', $num3+$num4)."x<br>\n";
echo "<b>Stap 3:</b> ".preg_replace('/\+\+/', '+', $num1+$num2)." / ".preg_replace('/\+\+/', '+', $num3+$num4)."x = ".$result."<br><br>\n";
echo "Het resultaat van <b>".$valueof1." ".$valueof2." = ".$valueof3." ".$valueof4."</b> is dus <b>".$result."</b>.<br><br>\n";
} else
echo "<font color=\"red\">* Vul een juiste vergelijking in.</font><br><br>\n";
}
echo "Voorbeeld invoer: 5x +3 = 2x +9.<br>\n";
echo "Voor een juist antwoord zijn + en - tekens nodig, vul deze in in het tweede tekst vakje(voor en na de '=')!<br>\n";
echo "<form method=\"post\">\n";
echo "<input type=\"text\" name=\"1\" value=\"".$valueof1."\"> <input type=\"text\" name=\"2\" value=\"".$valueof2."\"> = <input type=\"text\" name=\"3\" value=\"".$valueof3."\"> <input type=\"text\" name=\"4\" value=\"".$valueof4."\"><br>\n";
echo "<input type=\"submit\" value=\"Bereken!\">\n";
echo "</form>\n";
?>
</body>
</html>
<head>
<title>Lineaire vergelijkingen</title>
</head>
<body>
<?php
error_reporting(E_ALL);
$valueof1 = '';
$valueof2 = '';
$valueof3 = '';
$valueof4 = '';
if(isset($_POST['1'],$_POST['2'],$_POST['3'],$_POST['4'])) {
$_POST['1'] = preg_replace('/^([a-zA-Z]+?)$/','x', $_POST['1']);
$_POST['2'] = preg_replace('/^([a-zA-Z]+?)$/','x', $_POST['2']);
$_POST['3'] = preg_replace('/^([a-zA-Z]+?)$/','x', $_POST['3']);
$_POST['4'] = preg_replace('/^([a-zA-Z]+?)$/','x', $_POST['4']);
$valueof1 = ($_POST['1'] != 'x') ? htmlspecialchars($_POST['1']) : '1x';
$valueof2 = ($_POST['2'] != 'x') ? htmlspecialchars($_POST['2']) : '1x';
$valueof3 = ($_POST['3'] != 'x') ? htmlspecialchars($_POST['3']) : '1x';
$valueof4 = ($_POST['4'] != 'x') ? htmlspecialchars($_POST['4']) : '1x';
$points = 0;
$numbers = array();
$other = array();
if(is_numeric($valueof1)) {
$points += 1;
$numbers[] = $valueof1;
} else {
$points -= 1;
$other[] = ($valueof1 * -1).'x';
}
if(is_numeric($valueof2)) {
$points += 1;
$numbers[] = $valueof2;
} else {
$points -= 1;
$other[] = ($valueof2 * -1).'x';
}
if(is_numeric($valueof3)) {
$points += 1;
$numbers[] = $valueof3 * -1;
} else {
$points -= 1;
$other[] = $valueof3;
}
if(is_numeric($valueof4)) {
$points += 1;
$numbers[] = $valueof4 * -1;
} else {
$points -= 1;
$other[] = $valueof4;
}
if($points == 0) {
$num1 = $numbers[0];
$num2 = $numbers[1];
$num3 = $other[0];
$num4 = $other[1];
$result1 = preg_replace('/\+\+/', '+', $num1+$num2);
$result2 = preg_replace('/\+\+/', '+', $num3+$num4);
$result = $result1/$result2;
$plus1 = (substr($num2, 0, 1) == '-') ? '' : '+';
$plus2 = (substr($num4, 0, 1) == '-') ? '' : '+';
echo "<b>Invoer:</b> ".$valueof1.$valueof2." = ".$valueof3.$valueof4."<br>\n";
echo "<b>Stap 1:</b> ".$num1.$plus1.$num2." = ".$num3.$plus2.$num4."<br>\n";
echo "<b>Stap 2:</b> ".preg_replace('/\+\+/', '+', $num1+$num2)." = ".preg_replace('/\+\+/', '+', $num3+$num4)."x<br>\n";
echo "<b>Stap 3:</b> ".preg_replace('/\+\+/', '+', $num1+$num2)." / ".preg_replace('/\+\+/', '+', $num3+$num4)."x = ".$result."<br><br>\n";
echo "Het resultaat van <b>".$valueof1." ".$valueof2." = ".$valueof3." ".$valueof4."</b> is dus <b>".$result."</b>.<br><br>\n";
} else
echo "<font color=\"red\">* Vul een juiste vergelijking in.</font><br><br>\n";
}
echo "Voorbeeld invoer: 5x +3 = 2x +9.<br>\n";
echo "Voor een juist antwoord zijn + en - tekens nodig, vul deze in in het tweede tekst vakje(voor en na de '=')!<br>\n";
echo "<form method=\"post\">\n";
echo "<input type=\"text\" name=\"1\" value=\"".$valueof1."\"> <input type=\"text\" name=\"2\" value=\"".$valueof2."\"> = <input type=\"text\" name=\"3\" value=\"".$valueof3."\"> <input type=\"text\" name=\"4\" value=\"".$valueof4."\"><br>\n";
echo "<input type=\"submit\" value=\"Bereken!\">\n";
echo "</form>\n";
?>
</body>
</html>