Slip 8 - A) Write a PHP Script to create class Shape and its sub-class Triangle, Square, Circle and display area of selected shape (use concept of inheritance).

 Solution:

slip8-p1-q1.html

<HTML>
<BODY bgcolor=blue>
<FORM ACTION="slip8-p2-q1.php" METHOD="post">
<pre>
<h1>Circle:</h1>

        Radius: <input type=text name=a><BR>

<h1>
square:</h1>

        side: <input type=text name=b><BR>
<h1>
Rectangle:
</h1>
        length: <input type=text name=c><BR>

        Breadth: <input type=text name=d><BR>
<input type=submit value=submit> <input type="reset" value=cancel>
</pre>
</form>
</BODY>
</HTML>

slip8-p2-q1.php

<HTML>
<BODY>
<?PHP
$a=$_POST['a'];
$b=$_POST['b'];
$c=$_POST['c'];
$d=$_POST['d'];

interface one
{
        function area($c,$d);
}
class rect implements one
{
        function area($c,$d)
        {
                $area=$c*$d;
                echo"Area of rectangle......:".$area;
                echo"<br><BR>";
        }
}
class square extends rect
{
        function area($b,$f)
        {
                $area=$b*$f;
                echo"Area of Square.........:".$area;
                echo"<BR><br>";
        }
}
class circle
{
        function area($a)
        {
                $area=3.14*$a*$a;
                echo"Area of circle.........:".$area;
                echo"<br><BR>";
        }
}
$o=new rect();
$o->area($c,$d);
$s=new square();
$f=$b;
$s->area($b,$f);
$c=new circle();
$c->area($a);
echo "<br>";
?>
<a href="a4b1.html">come back</a><br>
</BODY>
</html>



Post a Comment

0 Comments