SDL Practical 5
SDL Practical 5
<?php
abstract class Shape {
abstract public function getArea();
}
<!DOCTYPE html>
<html>
<head>
<title>Area Calci</title>
</head>
<body>
<h2>Shape Selection</h2>
<form method="POST">
<input type="radio" name="shape" value="Triangle" required> Triangle
<input type="radio" name="shape" value="Square"> Square
<input type="radio" name="shape" value="Circle"> Circle</br><br>
Enter Dimensions:<br></br>
<input type="number" name="val1" placeholder="Enter first value" required>
<input type="number" name="val2" id="val2" placeholder="Enter second value (if needed)">
<input type="submit" name="submit" value="Calculate Area">
</form>
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$shapeType = $_POST['shape'];
$val1 = $_POST['val1'];
$val2 = isset($_POST['val2']) ? $_POST['val2'] : null;
$shape = null;
switch ($shapeType) {
case "Triangle":
if ($val2) {
$shape = new Triangle($val1, $val2);
} else {
echo "Please enter both base and height for the triangle.";
}
break;
case "Square":
$shape = new Square($val1);
break;
case "Circle":
$shape = new Circle($val1);
break;
}
if ($shape) {
echo "<h3>Area of $shapeType: " . $shape->getArea() . "</h3>";
}
}
?>
</body>
</html>