-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.php
More file actions
168 lines (146 loc) · 4.31 KB
/
test.php
File metadata and controls
168 lines (146 loc) · 4.31 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
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
<?php
session_start();
if (isset($_POST['click'])) {
$_POST['mx1'] = true;
$_POST['mx2'] = true;
$_POST['my1'] = true;
$_POST['my2'] = true;
$x1 = $_POST['x1'];
$y1 = $_POST['y1'];
$x2 = $_POST['x2'];
$y2 = $_POST['y2'];
if (!is_numeric($x1)) $_POST['mx1'] = false;
if (!is_numeric($y1)) $_POST['my1'] = false;
if (!is_numeric($x2)) $_POST['mx2'] = false;
if (!is_numeric($y2)) $_POST['my2'] = false;
$_SESSION['res'] = $_POST['mx1'] && $_POST['my1'] && $_POST['mx2'] && $_POST['my2'];
if ($_SESSION['res']) {
$z1 = new Complex($x1, $y1, 'z1');
$z2 = new Complex($x2, $y2, 'z2');
$z3 = Complex::sum($z1, $z2, 'z3');
$z4 = Complex::min($z1,$z2, 'z4');
$z5 = Complex::mul($z1, $z2, 'z5');
$z6 = Complex::dev($z1, $z2, 'z6');
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Комплексное число</title>
<style type="text/css">
.warning {
background-color: red;
}
</style>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
</head>
<body>
<div class="container">
<form action = '' method = "post" class="form form-controll">
<label>z1:</label>
<br>
<label>x:</label>
<?php if (!$_POST['mx1']) :?>
<label class="<?php echo (!$_POST['mx1'])?'warning':''?>">Ошибка</label>
<?php endif;?>
<input type="text" name="x1" placeholder="введите x" value="<?php echo ($_POST['mx1']) ? $_POST['x1'] : null ?>">
<label>y:</label>
<?php if (!$_POST['my1']) :?>
<label class="<?php echo (!$_POST['my1'])?'warning':''?>">Ошибка</label>
<?php endif;?>
<input type="text" name="y1" placeholder="введите y" value="<?php echo ($_POST['my1']) ? $_POST['y1'] : null ?>">
<br>
<label>z2:</label>
<br>
<label>x:</label>
<?php if (!$_POST['mx2']) :?>
<label class="warning">Ошибка</label>
<?php endif;?>
<input type="text" name="x2" placeholder="введите x" value="<?php echo ($_POST['mx2']) ? $_POST['x2'] : null ?>">
<label>y:</label>
<?php if (!$_POST['my2']) :?>
<label class="warning">Ошибка</label>
<?php endif;?>
<input type="text" name="y2" placeholder="введите y" value="<?php echo ($_POST['my2']) ? $_POST['y2'] : null ?>">
<br>
<input type="submit" name="click" value="Посчитать" class="btn btn-success">
</form>
<div class>
<?php if ($_SESSION['res']) :?>
<p>Вы ввели</p>
<?php
$z1->show();
$z2->show();
?>
<p>Результаты</p>
Сумма - <?php
$z3->show();
?>
Разность -<?php
$z4->show();
?>
Уможение -<?php
$z5->show();
?>
Деление - <?php
$z6->show();
?>
<?php endif;?>
</div>
</div>
</body>
</html>
<?php
class Complex {
private $x;
private $y;
private $name;
function __construct ($x, $y, $name = '')
{
$this->x = $x;
$this->y = $y;
$this->name = $name;
}
public function show ()
{
if ($this->name == 'mis') {
echo "Неверно были введены данные";
}
else {
echo $this->name . ' = ';
if ($this->x == 0) echo $this->y.'i'."<br>";
else if ($this->y > 0) echo $this->x . '+' . $this->y . 'i'."<br>";
else if ($this->y < 0) echo $this->x . $this->y . 'i'."<br>";
else echo $this->x."<br>";
}
}
public function getX() {
return $this->x;
}
public function getY() {
return $this->y;
}
public static function sum(Complex $z1, Complex $z2, $name) {
return new Complex($z1->getX()+$z2->getX(), $z1->getY()+$z2->getY(), $name);
}
public static function min(Complex $z1, Complex $z2, $name) {
return new Complex($z1->getX()-$z2->getX(), $z1->getY()-$z2->getY(), $name);
}
public static function mul(Complex $z1, Complex $z2, $name = '') {
return new Complex($z1->getX()*$z2->getX() - $z1->getY()*$z2->getY(),
$z1->getX()*$z2->getY()+$z2->getX()*$z1->getY(), $name);
}
public static function dev(Complex $z1, Complex $z2, $name) {
if ($z2->getX() != 0 || $z2->getY() != 0) {
$z2_ = new Complex($z2->getX(), -$z2->getY());
$numerator = self::mul($z1, $z2_);
$deminator = self::mul($z2, $z2_);
return new Complex($numerator->getX()/$deminator->getX(),
$numerator->getY()/$deminator->getX(), $name);
} else {
return new Complex(null,null, 'mis');
}
}
}
?>