9.
Create
an abstract class Shape with methods calc_area( ) and calc_volume( ). Derive
three classes Sphere(radius) , Cone(radius, height) and Cylinder(radius,
height), Calculate area and volume of all. (Use Method overriding).
Html file
:
<html>
<body>
<form
action="slip9.php" method=get>
<center><h2>For
Cone & Cylinder</h2>
Enter Radius
</td><td><input type="text"
name="r">
Enter Height</td><td>
<input type="text" name="h">
<input
type="submit" value="SUBMIT">
</form>
</body>
</html>
Php file
:
<?php
define('pi',3.14);
abstract
class shape
{
abstract function calc_area($r,$h);
abstract function calc_vol($r,$h);
}
class sphere
extends shape
{
function calc_area($r,$r)
{
return 4*pi*$r*$r;
}
function calc_vol($r,$r)
{
return (4/3)*pi*$r*$r*$r;
}
}
class
cylinder extends shape
{
function calc_area($r,$h)
{
return 2*pi*$r*($r+$h);
}
function calc_vol($r,$h)
{
return pi*$r*$r*$h;
}
}
class cone
extends shape
{
function calc_area($r,$h)
{
return 0.5*$r*$r*$h;
}
function calc_vol($r,$h)
{
return $r*$r*$r*$h;
}
}
$r=$_GET['r'];
$h=$_GET['h'];
$ob=new
cone();
echo
"Area of cone ".$ob->calc_area($r,$h);
echo "</br>";
echo
"Volume of cone ".$ob->calc_vol($r,$h);
echo "</br>";
$ob=new
cylinder();
echo
"Area of cylinder ".$ob->calc_area($r,$h);
echo "</br>";
echo
"Volume of cylinder".$ob->calc_vol($r,$h);
echo "</br>";
$ob=new
sphere();
echo
"Area of sphere ".$ob->calc_area($r,$r);
echo "</br>";
echo
"Volume of sphere ".$ob->calc_vol($r,$r);
?>
Nice way of expressing your ideas with us.thanks for sharing with us and please add more information's.
ReplyDeleteJAVA Training in Chennai
Best JAVA Training institute in Chennai
SEO training in chennai
Python Training in Chennai
Selenium Training in Chennai
Big data training in chennai
Selenium Training in Chennai
JAVA training in Annanagar
Java courses in chennai anna nagar