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.
49 lines
1.1 KiB
49 lines
1.1 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 carre extends rectangle
|
|
{
|
|
function __construct($c)
|
|
{
|
|
parent::__construct($c,$c);
|
|
}
|
|
}
|
|
|
|
$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();
|