You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
63 lines
1.5 KiB
63 lines
1.5 KiB
<?php
|
|
abstract class forme
|
|
{
|
|
abstract function surface();
|
|
abstract function perimetre();
|
|
}
|
|
|
|
class rectangle extends forme
|
|
{
|
|
protected $longeur;
|
|
protected $largeur;
|
|
|
|
function __construct($longeur, $largeur)
|
|
{
|
|
$this->longeur = $longeur;
|
|
$this->largeur = $largeur;
|
|
}
|
|
|
|
function surface()
|
|
{
|
|
return $this->longeur * $this->largeur;
|
|
}
|
|
|
|
function perimetre()
|
|
{
|
|
return 2 * $this->longeur + 2 * $this->largeur;
|
|
}
|
|
}
|
|
|
|
class triangle_rectangle extends forme
|
|
{
|
|
protected $hauteur;
|
|
protected $base;
|
|
|
|
function __construct($h, $b)
|
|
{
|
|
$this->hauteur = $h;
|
|
$this->base = $b;
|
|
}
|
|
|
|
function hypothenuse()
|
|
{
|
|
return sqrt($this->hauteur*$this->hauteur + $this->base*$this->base);
|
|
}
|
|
|
|
function surface()
|
|
{
|
|
return ($this->hauteur * $this->base) / 2;
|
|
}
|
|
|
|
function perimetre()
|
|
{
|
|
return $this->hauteur + $this->base + $this->hypothenuse();
|
|
}
|
|
}
|
|
|
|
$triangle_rectangle = new triangle_rectangle(4,3);
|
|
echo ". Un triangle rectangle de 4 par 3 a un périmètre de ";
|
|
echo $triangle_rectangle->perimetre();
|
|
echo " une hypothénuse de ";
|
|
echo $triangle_rectangle->hypothenuse();
|
|
echo " et une surface de ";
|
|
echo $triangle_rectangle->surface(); |