Wednesday, 27 December 2017

AWT-Slip9

1)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).           


<?php

abstract class Shape
{
 private $x = 0;
 private $y = 0;
 public abstract function area();
}

class Rectangle extends Shape
{
 function __construct($x, $y)
{
 $this->x = $x;
 $this->y = $y;
  }

 function area() {
return $this->x * $this->y;
 }
}

class Square extends Shape 
{
 function __construct($x) {
 $this->x = $x;
 }

function area() {
return $this->x * $this->x;
 }
}

$s = new Square(5);
 echo "<br>Square Area : ".$s->area();

  $r=new Rectangle(12, 4);
  echo "<br>Rectangle Area : ".$r->area();
?>

    

2) Write an Ajax program to print the content of themyfile.dat. This code asks the user to click a button, fetches data from theserver using Ajax techniques and displays that data in the same web page as the button without refreshing the page         


Fetchdata.php
<html>
<head>
<script LSNGUAGE="JavaScript">
var XHRobj = false;
if(window.XMLHttpRequest)
{
 XHRobj=new XMLHttpRequest();
}
else if(window.ActiveXObject)
{
XHRobj=new ActiveXObject("Microsoft.XMLHTTP");
}
function fetchdata(datasource,divID)
{
if(XHRobj)
{
XHRobj.open("GET",datasource);
XHRobj.onreadystatechange = function()
{
if(XHRobj.readyState == 4 && XHRobj.status == 200)
{
document.getElementById(divID).innerHTML = XHRobj.responseText;
}
}
XHRobj.send(null);
}
}
</script>
</head>
<body>
<form>
<input type="button" value="Fetch Message" onclick="fetchdata('myfile.dat','myDiv')" />
</form>
<div id="myDiv"><b>Fetched data will be shown here...</b></div>
</body>
</html>    
      
myfile.dat
This is an fetch data from dat file