Slip no. 15. Write a PHP program to define Interface shape which has two method as area() and volume (). Define a constant PI
Create a class Cylinder implement this interface and calculate area and Volume.

HTML file :
<h2> Calculate area and value of cylinder</h2>
<form action="slip1_demo.php" method="GET">
<h3>   Enter radius : <input type=text name=r><br>  </h3>
<h3>   Enter height : <input type=text name=h><br><br>  </h3>
<input type=submit value=submit name=Show>
<input type=reset value=Reset name=Reset>

PHP file :
$r    =   $_GET['r'];
$h   =   $_GET['h'];

interface cal
                                function area($r,$h);
                                function vol($r,$h);
class cylinder implements cal
                                function area($r,$h)
                                                $area  =  2*PI*$r*($r+$h);
                                                echo "<h3>The area of cylinder is :$area</h3>";     
                                function vol($r,$h)
                                                $vol  =  PI*$r*$r*$h;
                                                echo "<h3>The volume of cylinder is :$vol</h3>";  
$c   =  new cylinder;

1 comment:

Note: only a member of this blog may post a comment.