<!--
10]Write class
declarations and member function definitions for an 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 menu driven PHP program a) to build a master table b) to sort all
entries c) to search an entry d) Display salary-->
<html>
<form class="" action="SLIP10.php"
method="post">
<input type="radio" name="rad"
value="1">Build a Master Table <br><br>
<input type="radio" name="rad"
value="2">Sort all entries <br><br>
<input type="radio" name="rad"
value="3">Search an entry by Employee's Name
<input type="text" name="ename">
<br><br>
<input type="radio" name="rad"
value="4">Display Salary <br><br>
<input type="submit" name="sub"
value="Submit">
</body>
</html>
Slip10.php
class
employee
{
public
$code,$name,$desig;
function
__construct($a,$b,$c)
{
$this->code=$a;
$this->name=$b;
$this->desig=$c;
}
public
function display_emp()
{
echo'
<td>'.$this->code.'</td>
<td>'.$this->name.'</td>
<td>'.$this->desig.'</td>
';
}
{
return
$this->name;
}
class emp_acc extends employee
{
public
$ano,$jdate;
function
__construct($a,$b,$c,$d,$e)
{
parent::__construct($a,$b,$c);
$this->ano=$d;
$this->jdate=$e;
}
public
function display_acc()
{
echo'
<td>'.$this->ano.'</td>
<td>'.$this->jdate.'</td>
';
}
}
class
emp_sal extends emp_acc
{
public
$bpay,$earns,$ded,$total;
function
__construct($a,$b,$c,$d,$e,$f,$g,$h)
{
parent::__construct($a,$b,$c,$d,$e);
$this->bpay=$f;
$this->earns=$g;
$this->ded=$h;
$this->total=$this->bpay
+ $this->earns - $this->ded;
}
public
function display_sal()
{
echo'
<td>'.$this->bpay.'</td>
<td>'.$this->earns.'</td>
<td>'.$this->ded.'</td>
<td>'.$this->total.'</td>
';
}
}
$emp[0]=new emp_sal('A923B','Ramesh','Staff','10001','21/09/2011','20000','5000','3000');
$emp[1]=new
emp_sal('A823B','Ram','HR','10002','22/09/2011','25000','5000','3000');
$emp[2]=new
emp_sal('A723B','Sita','Analyst','10003','23/09/2011','22000','5000','3000');
$emp[3]=new
emp_sal('A623B','Gita','Organiser','10004','24/09/2011','21000','5000','3000');
$ename=$_POST['ename'];
$flag=0;
{
echo
'<table border="1" width="100%">
<tr>
<th>Code</th>
<th>Name</th>
<th>Designation</th>
<th>Ac
No</th>
<th>Join
date</th>
<th>Basic
Pay</th>
<th>Earnings</th>
<th>Deduction</th>
<th>Total
Salary</th>
for($i=0;$i<4;$i++)
{
echo
'<tr>';
$emp[$i]->display_emp();
$emp[$i]->display_acc();
$emp[$i]->display_sal();
echo
'</tr>';
}
echo
'</table>';
}
{
case
1:
mastertable($emp);
break;
case
2: echo 'Sorting Employee Code
<br><br>';
function
srt($a,$b)
{
return
strcmp($a->code,$b->code);
}
usort($emp,"srt");
break;
case
3: echo "Searching for employee $ename .....<br><br>";
for($i=0;$i<4;$i++)
{
$temp=$emp[$i]->getname();
if($temp==$ename)
{
$flag=1;
break;
}
}
if($flag==0)
{
echo
"Not Found<br>";
}
else
{
echo
"Found in the records<br>";
break;
case
4: echo "Displaying Salary of all Employees ....
<br><br>";
echo
'<table border="1" width="100%">
<tr>
<th>Employee
Name</th>
<th>Basic
Pay</th>
<th>Earnings</th>
<th>Deduction</th>
<th>Total
Salary</th>
for($i=0;$i<10;$i++)
{
echo
'<tr>
<td>'.$emp[$i]->getname().'</td>
';
$emp[$i]->display_sal();
break;
?>