} public function mass() { return $this->r * $this->volume(); } } $cube = new Cube(5, 4, 3); $parallelepiped = new Parallelepiped(5, 4, 3, 10, 11); $pyramid = new Pyramid(5, 4, 3, 10, 2); $sphere = new Sphere(5, 4); echo "---------------------------------------------------------------------------------------------------------------------<br>"; echo "Основне завдання : <br><br>"; echo "Куб : <br>"; echo "Площа - " . $cube->square() . "<br>"; echo "Об'єм - " . $cube->volume() . "<br>"; echo "Маса - " . $cube->mass() . "<br><br>"; echo "Параллелепіпед : <br>"; echo "Площа - " . $parallelepiped->square() . "<br>"; echo "Об'єм - " . $parallelepiped->volume() . "<br>"; echo "Маса - " . $parallelepiped->mass() . "<br><br>"; echo "Піраміда : <br>"; echo "Площа - " . $pyramid->square() . "<br>"; echo "Об'єм - " . $pyramid->volume() . "<br>"; echo "Маса - " . $pyramid->mass() . "<br><br>"; echo "Куля : <br>"; echo "Площа - " . $sphere->square() . "<br>"; echo "Об'єм - " . $sphere->volume() . "<br>"; echo "Маса - " . $sphere->mass() . "<br><br>"; echo "---------------------------------------------------------------------------------------------------------------------<br>"; echo "Додаткове завдання : <br><br>"; //----------------------------------------------------------------------------------------------
parent::__construct($a, $p, $name); } public function V() { return $this->a * $this->h * $this->h_o / 6; } } class Parallelepiped extends Figure { private $b; private $c; function __construct($a, $b, $c, $p, $name) { $this->b = $b; $this->c = $c; parent::__construct($a, $p, $name); } public function V() { return $this->a * $this->b * $this->c; } } $cube = new Cube(4, 5, "Куб"); $ball = new Ball(3, 5, "Куля"); $pyramid = new Pyramid(3, 5, 7, 5, "Піраміда"); $parallelepiped = new Parallelepiped(4, 5, 6, 5, "Паралелипіпит"); $c = $cube->name . ": " . "Об’єм = " . $cube->V() . "; " . "Маса = " . $cube->mass() . "; " . "Густина = " . $cube->p . "\n"; $b = $ball->name . ": " . "Об’єм = " . $ball->V() . "; " . "Маса = " . $ball->mass() . "; " . "Густина = " . $ball->p . "\n"; $p = $pyramid->name . ": " . "Об’єм = " . $pyramid->V() . "; " . "Маса = " . $pyramid->mass() . "; " . "Густина = " . $pyramid->p . "\n"; $a = $parallelepiped->name . ": " . "Об’єм = " . $parallelepiped->V() . "; " . "Маса = " . $parallelepiped->mass() . "; " . "Густина = " . $parallelepiped->p . "\n"; echo $c, $b, $p, $a;