<!-- Inhalt der Datei okreis.php -->
<html>
<head>
<?
//die Klasse mit dem Namen Kreis definieren
class Kreis
{
private $radius;
public function __construct($r)
{
$this->radius=$r;
}
public function flaeche()
{
$pi=pi();
$a=$this->radius*$this->radius*$pi;
return $a;
}
public function umfang(&$u)
{
$pi=pi();
$u=2*$this->radius*$pi;
}
}
$radius=$was="";
if (isset($_GET['knopf']))
{
$radius=$_GET['r'];
$was=$_GET['was'];
//ein Objekt aus der Klasse Kreis erzeugen
$kreis=new Kreis($radius);
if ($was == "U" || $was == "u" )
{
$kreis->umfang($um);
echo "Der Umfang des Kreises beträgt $um mm.";
}
else if ($was == "F" || $was == "f" )
{
$fl=$kreis->flaeche();
echo "Die Fläche des Kreises beträgt $fl mm<sup>2</sup>.<br>";
}
else
echo "Keine gültige Berechnungsart gewählt.";
}
?>
</head>
<body>
<h2>Kreis: Umfang und Fläche <br>(Textfeld)</h2>
<form action="./okreis.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>U/F:</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>