1)Write a PHP program to
create a simple calculator that can accept two numbers and perform operations
like add, subtract, multiplication and divide (using Self Processing form)
<HTML>
<BODY>
<form method="post" action="<?php echo
$_SERVER['PHP_SELF']?>">
<B>First Number:</b><input type="text"
name="num1">
<B>Second Number:</b><input type="text"
name="num2">
<input type="radio" name="cal" value="add">
Add
<input type="radio" name="cal" value="sub">
Sub
<input type="radio" name="cal"
value="mult"> Multy
<input type="radio" name="cal" value="div">
Division
<input type="submit" name="submit">
</form>
<?php
if(isset($_POST['submit']))
{
$n1=(int)$_POST['num1'];
$n2=(int)$_POST['num2'];
$c=trim($_POST['cal']);
if(strcmp($c,"add") == 0){$result=$n1+$n2;
echo"$n1+$n2=$result";}
if(strcmp($c,"sub")== 0){$result=$n1-$n2;
echo"$n1-$n2=$result";}
if(strcmp($c,"mult")== 0){$result=$n1*$n2;
echo"$n1*$n2=$result";}
if(strcmp($c,"div")== 0){$result=$n1/$n2;
echo"$n1/$n2=$result";}
}
?>
</body>
</html>
2)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) andDisplay details of Employees who having
Maximum and Minimum Salary.
<?php
class Employee
{
public $eid,$ename,$edesg;
function __construct($a,$b,$c)
{
$this->eid=$a;
$this->ename=$b;
$this->edesg=$c;
}
public function getdata()
{
return $this->sal;
}
public function display()
{
echo $this->eid."</br>";
echo $this->ename."</br>";
echo $this->edesg."</br>";
//echo $this->ename."</br>";
}
}
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;
//public static $total1=0;
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;
}
public function max($ob)
{
//$sal=$this->getdata();
$total=$this->b_pay+$this->er;
$total=$total-$this->dud;
if($total>self::$total1)
{
self::$total1=$total;
return $this;
}
else
{
return $ob;
}
}
public function min($ob)
{
//$sal=$this->getdata();
$total=$this->b_pay+$this->er;
$total=$total-$this->dud;
if($total<self::$total1)
{
self::$total1=$total;
return $this;
}
else
{
return $ob;
}
}
public function display()
{
echo $this->ename;
}
}
$ob=new Emp_sal(0,"ABC","",0,"",0,0,0);
$temp=new Emp_sal(0,"ABC","",0,"",0,0,0);
$ob1=new
Emp_sal(1,"aaaaa","HOD",123411,"12-10-2018",28000,2000,500);
$ob=$ob1->max($ob);
$temp=$ob1->min($temp);
$ob2=new
Emp_sal(1,"bbbbb","HOD",123411,"12-10-2018",48000,2000,500);
$ob=$ob2->max($ob);
$temp=$ob2->min($temp);
$ob3=new
Emp_sal(1,"ccccc","HOD",123411,"12-10-2018",58000,2000,500);
$ob=$ob3->max($ob);
$temp=$ob3->min($temp);
$ob4=new
Emp_sal(1,"ddddd","HOD",123411,"12-10-2018",8000,2000,500);
$ob=$ob4->max($ob);
$temp=$ob4->min($temp);
$ob5=new
Emp_sal(1,"eeeee","HOD",123411,"12-10-2018",7000,2000,500);
$ob=$ob5->max($ob);
$temp=$ob5->min($temp);
$ob->display();
$temp->display();
?>