TY_BCA_AWT_SLIP 3_2



1.     Derive a class square from class Rectangle. Create one more class circle. Create an interface with only one method called area (). Implement this interface in all the classes. Include appropriate data members and constructors in all classes. Write a program to accept details of a square, circle and rectangle and display the area.

Html file :

<html>
<body>
<form action="slip_3.php" method="get">

<h2>  Square :   </h2>
Enter side for Square : <input type="text" name=s>

<h2>  Rectangle :   </h2>
Enter length  : <input type="text" name=l>  <br>
Enter breath : <input type="text" name=b>

<h2>  Circle :   </h2>
Enter radius : <input type="text" name=r>  <br>

<input type="submit" name=submit value=Submit>
<input type="reset" name=reset value=reset>

</form>
</body>
</html>

Php file :

<?php
$s  =   $_GET['s'];
$l   =   $_GET['l'];
$b  =   $_GET['b'];
$r   =   $_GET['r'];

interface findarea
{
                     function area($l,$c);
}

class rectangle implements findarea
{
                     function area($l,$b)
                     {
                                 $area  =  $l*$b;
                                 echo "Area of Rectanle :".$area."<br>";          
                     }
}

class square extends rectangle
{
                     function area($s,$s)
                     {
                                 $area  =  $s*$s;
                                 echo "Area of Square :". $area."<br>";           
                     }
}

class circle
{
                     function area($r)
                     {
                                 $area  =  0.5*$r*$r;
                                 echo "Area of Circle :". $area."<br>";  
                     }
}

$fr  =  new rectangle;
$fr->area($l,$b);

$fs  =  new square;
$fs->area($s,$s);

$fc  =  new circle();
$fc->area($r)
?>

3 comments:

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