






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
This document cover the objected oriented program based on PHP
Typology: Study notes
1 / 11
This page cannot be seen from the preview
Don't miss anything!







Write class declarations and member function definitions for following:
Employee(code, name, designation). Design derived classes as emp_account(account_no, joining_date) from employee and emp_sal(basic_pay, earnings, deduction) from emp_account. Write a PHP Script to create 5 objects (pass details using parameterized constructor) and display details of employees having maximum and minimum Salary.
eid=$a; $this->ename=$b; $this->edesg=$c; } public function getdata() { return $this->sal; } public function display() { echo $this->eid.""; echo $this->ename.""; echo $this->edesg.""; //echo $this->ename.""; } } class Emp_account extends Employee { public $ac_no,$jdate; public static $total1=0; function __construct($a,$b,$c,$d,$e) { parent::__construct($a,$b,$c); $this->ac_no=$d; $this->jdate=$e; } } class Emp_sal extends Emp_account { public $b_pay,$er,$dud;
function __construct($a,$b,$c,$d,$e,$f,$g,$h) { parent::__construct($a,$b,$c,$d,$e); $this->b_pay=$f; $this->er=$g;
$this->dud=$h;
$temp=$ob4->min($temp); $ob5=new Emp_sal(1,"ram","lecturer",1234,"21/3/2018",7000,2000,500); $ob=$ob5->max($ob); $temp=$ob5->min($temp); $ob->display(); $temp->display();
?>
2.Define an interface which has methods area(), volume(). Define constant PI. Create a class cylinder which implements this interface and calculate area and volume. (Use define())
Calculate area and value of cylinder
Enter radius : Enter height :
Php file :
The area of cylinder is :$area"; }
function vol($r,$h) { $vol = PI$r$r*$h; echo "The volume of cylinder is :$vol";
$c = new cylinder; $c->area($r,$h); $c->vol($r,$h);
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 :
Square : Enter side for Square :
Rectangle : Enter length : Enter breath :
Circle : Enter radius :
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) {
public function display() { echo $this->eid.""; echo $this->ename.""; echo $this->edept.""; //echo $this->ename.""; } } class Manager extends Employee { private $bonus; public static $total1=0; function __construct($a,$b,$c,$d,$e) { parent::__construct($a,$b,$c,$d); $this->bonus=$e; } public function max($ob) { $sal=$this->getdata(); $total=$sal+$this->bonus; if($total>self::$total1) { self::$total1=$total; return $this; } else { return $ob; } } public function display() { parent::display(); echo self::$total1; }
$ob=new Manager(0,"ABC","",0,0); $ob1=new Manager(1,"sonia","f",28000,2000); $ob=$ob1->max($ob); $ob2=new Manager(2,”aarti","c",3000,2500); $ob=$ob2->max($ob); $ob3=new Manager(3,"rani","d",3200,3000); $ob=$ob3->max($ob); $ob4=new Manager(4,"kirti","g",28000,4000); $ob=$ob4->max($ob); $ob5=new Manager(5,"anu","r",28000,5000); $ob=$ob5->max($ob); $ob->display();
Write a PHP Script to create a super class Vehicle having members Company and price.Derive 2 different classes LightMotorVehicle (members – mileage) and HeavyMotorVehicle (members – capacity-in-tons). Define 5 Object of each subclass and display details in table format.
company=$a; $this->price=$b; } } class Lightmotorvehicle extends vehicle { public $milege; public function __construct($a,$b,$c) { $this->company=$a; $this->price=$b; $this->milege=$c; } public function display() { echo "".$this->company."".$this->price."".$this- >milege.""; } } class Heavymotorvehicle extends vehicle { public $capacity; public function __construct($a,$b,$c) { $this->company=$a; $this->price=$b; $this->capacity=$c; } public function display() { echo ""; echo "".$this->company."".$this->price."".$this->capacity; echo ""; } } $ob1=new Lightmotorvehicle("",,); $ob1->display(); $ob2=new Lightmotorvehicle("",,); $ob2->display(); $ob3=new Lightmotorvehicle("",,); $ob3->display();
$ob4=new Heavymotorvehicle("Tata Truck",123,25); $ob4->display(); $ob5=new Heavymotorvehicle("Bajaj",200000,25); $ob5->display();
var_dump(get_object_vars($ob)); //retuns an array of parameter / variables for given object ?>
Html file :
For Cone & Cylinder Enter Radius Enter Height
Php file :
php
define('pi',3.14); abstract class shape {
abstract function calc_area($r,$h); abstract function calc_vol($r,$h);
class sphere extends shape { function calc_area($r,$r) { return 4pi$r*$r; }
function calc_vol($r,$r) { return (4/3)pi$r$r$r; } }
class cylinder extends shape { function calc_area($r,$h) { return 2pi$r*($r+$h); }
function calc_vol($r,$h) {
return pi$r$r*$h; } }
class cone extends shape { function calc_area($r,$h) { return 0.5$r$r*$h; }
function calc_vol($r,$h) { return $r$r$r*$h; } } $r=$_GET['r']; $h=$_GET['h']; $ob=new cone(); echo "Area of cone ".$ob->calc_area($r,$h); echo ""; echo "Volume of cone ".$ob->calc_vol($r,$h); echo ""; $ob=new cylinder(); echo "Area of cylinder ".$ob->calc_area($r,$h); echo ""; echo "Volume of cylinder".$ob->calc_vol($r,$h); echo "";
$ob=new sphere(); echo "Area of sphere ".$ob->calc_area($r,$r); echo ""; echo "Volume of sphere ".$ob->calc_vol($r,$r);