Define an interface which has methods area(), volume(). Define constant
PI. Create a class cylinder which implements this interface and calculate
area and volume. (Hint: Use define())
<?php
define('PI','3.142');
interface cal
{
function area();
function volume();
}
class cylinder implements cal
{
var $r;
var $h;
function setValue($r,$h)
{
$this->r=$r;
$this->h=$h;
}
function area()
{
$a=2*PI*$this->r*($this->r+$this->h);
echo "AREA OF CYLINDER= :$a";
echo "<br>";
}
function volume()
{
$v=PI*$this->r*$this->r*$this->h;
echo "VOLUME OF CYLINDER= :$v";
echo "<br>";
}
}
$c=new cylinder();
$c->setValue(2,3);
$c->area();
$c->volume();
?>
0 Comments
If anyone has Doubts or suggestions please let me know