<html>
<head>
<?
//Elternklasse
class Kreis
{
protected $radius;
public function __construct($r)
{
$this->radius=$r;
}
public function flaeche()
{
$pi=3.14159;
$a=$this->radius*$this->radius*$pi;
return $a;
}
public function umfang()
{
$pi=3.14159;
$u=2*$this->radius*$pi;
return $u;
}
}
//Kindklasse von Kreis
class Zylinder extends Kreis
{
private $hoehe;
public function __construct($r,$h)
{
$this->radius=$r;
$this->hoehe=$h;
}
public function volumen(&$v)
{
//Aufruf der Methode flaeche() aus der Elternklasse
$a=$this->flaeche();
$v=$a*$this->hoehe;
}
public function oberflaeche(&$o)
{
//Aufruf der Methode flaeche() aus der Elternklasse
$a=$this->flaeche(); // Kreisflaeche
$o=2*$a + $this->umfang()*$this->hoehe;
}
}
$radius=$hoehe=$was="";
if (isset($_GET['knopf']))
{
$radius=$_GET['r'];
$hoehe=$_GET['h'];
$was=$_GET['was'];
if ($was == "Kreis")
{
//Kreisobjekt erzeugen
$kreis=new Kreis($radius);
$fl=$kreis->flaeche();
$um=$kreis->umfang();
echo "Die Fläche des Kreises beträgt $fl mm<sup>2</sup>.<br>";
echo "Der Umfang des Kreises beträgt $um mm.";
}
else if ($was == "Zylinder")
{
$zyl=new Zylinder($radius,$hoehe);
$zyl->volumen($vol);
$zyl->oberflaeche($ob);
echo "Das Volumen des Zylinders beträgt $vol mm<sup>3</sup>.<br>";
echo "Die Oberfläche des Zylinders beträgt $ob mm<sup>2</sup>.<br>";
}
else
echo "Keine gültige Berechnungsart gewählt.";
}
?>
</head>
<body>
<h2>Kreis oder<br>Zylinder</h2>
<form action="./ozylinder.php" method="get">
<table border="1">
<tr>
<td>Radius [mm]:</td>
<td><input type="text" name="r" size="6" value="<?=$radius?>"></td>
</tr>
<tr>
<td>Höhe [mm]</td>
<td><input type="text" name="h" size="6" value="<?=$hoehe?>"></td>
</tr>
<tr>
<td>Kreis/Zylinder:</td>
<td><input type="text" name="was" size="6" value="<?=$was?>"></td>
</tr>
<tr>
<td align="right" colspan="2"><input type="submit" name="knopf" value="Berechnung">
</tr>
</table>
</form>
</body>
</html>