<?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;
}
}
class MethodsOfTrapezoid
{
public static $sumSquare;
public static $averSquare;
public static $quantity = 0;
public static function CreateTrapezoids($n)
{
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));
self::$sumSquare += $trapecia[$i]->getSquare();
}
return $trapecia;
}
public static function QuantityCalc($n, $trapecia)
{
self::$averSquare = self::$sumSquare / $n;
for ($i = 0 ; $i < $n; $i++)
{
if($trapecia[$i]->getSquare() > self::$averSquare)
{
self::$quantity++;
}
}
}
public static function Show($n,$trapecia)
{
for($i = 0; $i < $n; $i++)
{
echo "Square of trapezoid " . $i ." : ".$trapecia[$i]->getSquare() . "\n<BR>";
echo "Perimeter of trapezoid " . $i ." : ".$trapecia[$i]->getPerimeter() . "\n<BR>";
if ($trapecia[$i]->isEquilateral())
{
echo "trapezoid " . $i . " is equilateral \n<BR>";
}
else {
echo "trapezoid " . $i . " is UNequilateral \n<BR>";
}
}
echo "average Square: ".self::$averSquare . "\n<BR>";
echo "Quantity of trapezoids which square more then average Square: ".self::$quantity . "\n<BR>";
}
}
$massTrapezoid = MethodsOfTrapezoid::CreateTrapezoids(4);
MethodsOfTrapezoid::QuantityCalc(4, $massTrapezoid);
MethodsOfTrapezoid::Show(4, $massTrapezoid);