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.

54 lines
826 B

<?php
class cercle
{
private $rayon;
function __construct($rayon)
{
$this->rayon = $rayon;
}
function surface()
{
return M_PI * $this->rayon * $this->rayon;
}
function rayon()
{
return $this->rayon;
}
function changer_rayon($rayon)
{
if($rayon < 0)
{
echo " Erreur : impossible de définir un cercle de rayon négatif! ";
}
else
{
$this->rayon = $rayon;
}
}
}
$cercle3 = new cercle(3);
echo $cercle3->surface();
echo " ";
$cercle5 = new cercle(5);
echo $cercle5->surface();
echo " ";
$cercleN = new cercle(2);
echo $cercleN->surface();
echo " ";
$cercleN->changer_rayon(7);
echo $cercleN->surface();
echo " ";
$cercleN->changer_rayon(-1);
echo $cercleN->rayon();