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.
76 lines
1.6 KiB
76 lines
1.6 KiB
<?php
|
|
abstract class forme
|
|
{
|
|
abstract function surface();
|
|
abstract function perimetre();
|
|
}
|
|
|
|
class cercle extends forme
|
|
{
|
|
private $rayon;
|
|
|
|
function __construct($rayon)
|
|
{
|
|
$this->rayon = $rayon;
|
|
}
|
|
|
|
function surface()
|
|
{
|
|
return M_PI * $this->rayon * $this->rayon;
|
|
}
|
|
|
|
function perimetre()
|
|
{
|
|
return M_PI * $this->rayon * 2;
|
|
}
|
|
}
|
|
|
|
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 carre extends rectangle
|
|
{
|
|
function __construct($cote)
|
|
{
|
|
$this->longeur = $cote;
|
|
$this->largeur = $cote;
|
|
}
|
|
}
|
|
|
|
$cercle = new cercle(3);
|
|
echo "Un cercle de rayon 3 a un périmètre de ";
|
|
echo $cercle->perimetre();
|
|
echo " et une surface de ";
|
|
echo $cercle->surface();
|
|
|
|
$rectangle = new rectangle(4,3);
|
|
echo ". Un rectangle de 4 par 3 a un périmètre de ";
|
|
echo $rectangle->perimetre();
|
|
echo " et une surface de ";
|
|
echo $rectangle->surface();
|
|
|
|
$carre = new carre(4);
|
|
echo ". Un carré de côté 4 a un périmètre de ";
|
|
echo $carre->perimetre();
|
|
echo " et une surface de ";
|
|
echo $carre->surface();
|