Решение задач
<?php
class Trapeci {
public $x1;
public $x2;
public $x3;
public $x4;
public $y1;
public $y2;
public $y3;
public $y4;
public $a;
public $b;
public $DA;
public $BC;
public $AB;
public $CD;
public $Dlina;
public $perimetr;
public $s;
function __construct ($x1,$y1,$x2,$y2,$x3,$y3,$x4,$y4) {
$this-> x1 = $x1 ;
$this-> y1 = $y1 ;
$this-> x2 = $x2 ;
$this-> y2 = $y2 ;
$this-> x3 = $x3 ;
$this-> y3 = $y3 ;
$this-> x4 = $x4 ;
$this-> y4 = $y4 ;
$this-> a= sqrt(pow( $this-> x4 - $this-> x3,2) + pow($this-> y4 - $this-> y3,2));
// echo "a :", $this-> a;
$this-> b= sqrt(pow( $this-> y2 - $this-> y1,2) + pow($this-> x2 - $this-> x1,2));
// echo " b :", $this-> b,"<BR>";
$this-> DA = sqrt(pow($this-> x4 - $this-> x1,2) + pow($this-> y4 - $this-> y1,2));
$this-> BC = sqrt(pow($this-> x3 - $this-> x1,2) + pow($this-> y3 - $this-> y1,2));
$this-> AB = sqrt(pow($this-> x2 - $this-> x1,2) + pow($this-> y2 - $this-> y1,2));
$this-> CD = sqrt(pow($this-> x4 - $this-> x3,2) + pow($this-> y4 - $this-> y3,2));
$this-> perimetr = $this-> DA + $this-> BC + $this-> AB + $this-> CD;
$this-> s = (($this-> DA+$this-> BC)/2)* sqrt( pow($this-> AB,2)- pow(($this-> DA-$this-> BC)/2,2) ) ;
}
function TestRavnobochnost () {
if ( $this-> a == $this-> b ) {
echo "<BR> Ravnobochnaya <BR> ";
}
else {
echo " <BR> NeRavnobochnaya <BR> ";
}
}
function Dlina () {
echo " DA: ", $this-> DA,"<BR>" ;
echo "BC: ",$this-> BC,"<BR>";
echo "AB: ",$this-> AB,"<BR>" ;
echo " CD: ", $this-> CD,"<BR>";
}
function Perimetr () {
echo " Perimetr: ", $this-> perimetr,"<BR>";
}
function Ploshad () {
echo " Ploshad: ", $this-> s, "<BR>";
}
function __destruct () {
$this-> x1;
$this-> y1 ;
$this-> x2 ;
$this-> y2;
$this-> x3 ;
$this-> y3;
$this-> x4 ;
$this-> y4;
$this-> s;
$this-> perimetr;
$this-> Dlina;
}
}
$N=3;
for ( $i = 0; $i < $N; $i++) {
$objs[$i] = new Trapeci (rand(5,20),rand(5,20),rand(5,20),rand(5,20),rand(5,20),rand(5,20),rand(5,20),rand(5,20));
$objs[$i]-> TestRavnobochnost ();
$objs[$i]-> Dlina ();
$objs[$i]-> Perimetr ();
$objs[$i]-> Ploshad ();
$summaploshad += $objs[$i]-> s;
}
$srefnyaploshad = $summaploshad/$N;
$k=0;
for ( $i = 0; $i < $N; $i++) {
if ($objs[$i]-> s > $srefnyaploshad) {
$k =$k +1;
}
}
echo "<BR> <BR> <BR> Summa ploshad: ", $summaploshad, "<BR>";
echo $summaploshad, "/",$N, " Srednya ploshad: ", $srefnyaploshad, "<BR>" ;
echo "Kolichtstvo trapecii ploshad bolshe srednei: ", $k;
?>
math2
Fri, 06/19/2020 - 16:44
Permalink
Приветствую!
Приветствую!
Перепишите это частично, применяя английскую терминологию и используя класс Point для точки:
class Point { public $x; public $y; function __construct($x, $y) { $this->x = $x; $this->y = $y; } /** * Distance to another point */ function distance(Point $point) { } }И далее перепишите Trapeci, используя черыре точки:
class Trapezoid { public $A; public $B; public $C; public $D; /** * Равнобочность */ function isEquilateral(): bool { } function getPerimeter() { } function getSquare() { } }fgh
Sun, 06/21/2020 - 22:50
Permalink
<?php
<?php class Point { public $x; public $y; function __construct($x, $y) { $this->x = $x; $this->y = $y; } function distance(Point $point) { return sqrt(pow($this-> x - $point-> x,2 )+pow( $this-> y - $point-> y, 2)); } } class Trapezoid { public $AB; public $BC; public $CD; public $DA; public $h; public $perimetr; public $s; public function __construct($x1, $y1, $x2, $y2, $x3, $y3, $x4, $y4) { $A = new Point($x1, $y1); $B = new Point($x2, $y2); $C = new Point($x3, $y3); $D = new Point($x4, $y4); $this->AB = $A->distance($B); $this->BC = $B->distance($C); $this->CD = $C->distance($D); $this->DA = $D->distance($A); $this->h = sqrt(pow($this->AB,2)-pow(($this->DA - $this->BC )/2,2)); } function isEquilateral() : bool { return $this->AB == $this->CD; } function getSquare() { $this->s = ($this->BC+$this->DA) / 2 * $this->h; return $this->s; } function getPerimeter() { $this->perimetr = $this->AB + $this->BC + $this->CD + $this->DA; return $this->perimetr; } } $n = 4; $sumSquare = 0; $averSquare = 0; for ($i = 0; $i < $n; $i++) { $trapecia[$i] = new Trapezoid(rand(5, 10), rand(5, 10), rand(5, 10), rand(5, 10), rand(5, 10), rand(5, 10), rand(5, 10), rand(5, 10)); echo "Perimeter" .$i . "trapeziod : " . $trapecia[$i]->getPerimeter() . "\n"; echo "Square" .$i . "trapeziod : " . $trapecia[$i]->getSquare() . "\n"; if ($trapecia[$i]->isEquilateral()) { echo "trapezoid" . $i . "is equilateral \n"; } else { echo "trapezoid" . $i . "is UNequilateral \n"; } $sumSquare += $trapecia[$i]->getSquare(); } $averSquare = $sumSquare / $n; $counter = 0; for ($i = 0 ; $i < $n; $i++) { if($trapecia[$i]->getSquare() > $averSquare) { $counter++; } } echo "Average square: " . $averSquare . "\n"; echo "Quantity of trapezoid which square more then Average square: " . $counter . "\n";