Advanced Web Technology
Slip1
Q.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) [15]
Solution
<html>
<body>
<FORM ACTION="<?php $_SERVER['PHP_SELF']; ?>"
method="POST">
<table>
<tr><td><h3>Enter first no :</td><td><input type=text
name=no1 ></h3></td></tr>
<tr><td><h3>Enter second no :</td><td><input type=text
name=no2></h3></td></tr>
<tr><td><b>Select Operation which u have to perform :</b></td>
<td><select name=cal>
<option value="1">Addition</option>
<option value="2">Substraction</option>
<option value="3">Multiplication</option>
<option value="4">Division</option>
</select></td></tr>
<tr><td></td><td><input type=submit name=submit
value=Calculate></td></tr>
</table>
</form>
</body>
</html>
<?php
if(isset($_POST['submit']))
{
$no1=$_POST['no1'];
$no2=$_POST['no2'];
$cal=$_POST['cal'];
if((!empty($no1)) && (!empty($no2)))
{
switch($cal)
{
case 1:$add=$no1+$no2;
echo "<h1>addition=".$add."</h1>";
break;
case 2:$sub=$no1-$no2;
echo "<h1>subtraction=".$sub."</h1>";
break;
case 3:$mult=$no1*$no2;
echo
"<h1>multiplication=".$mult."</h1>";
break;
case 4:$div=$no1/$no2;
echo
"<h1>division=".$div."</h1>";
break;
}
}
else echo "<b>Please enter both 2 nos</b>";
}
else
die("not able to acccess");
?>
Q.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) and Display details of Employees who having Maximum and Minimum Salary. [25]
Solution
<?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()
{
// parent::display();
echo $this->ename;
//echo self::$total1;
}
}
$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,"ramdas","HOD",1234,"21/3/2015",28000,2000,500);
$ob=$ob1->max($ob);
$temp=$ob1->min($temp);
$ob2=new Emp_sal(1,"ramdas1","HOD",1234,"21/3/2015",48000,2000,500);
$ob=$ob2->max($ob);
$temp=$ob2->min($temp);
$ob3=new Emp_sal(1,"ramdas2","HOD",1234,"21/3/2015",58000,2000,500);
$ob=$ob3->max($ob);
$temp=$ob3->min($temp);
$ob4=new Emp_sal(1,"ramdas3","HOD",1234,"21/3/2015",8000,2000,500);
$ob=$ob4->max($ob);
$temp=$ob4->min($temp);
$ob5=new Emp_sal(1,"ramdas4","HOD",1234,"21/3/2015",7000,2000,500);
$ob=$ob5->max($ob);
$temp=$ob5->min($temp);
$ob->display();
$temp->display();
?>
Tags:
Advanced Web Technology
Please send me the slip
ReplyDeleteAWT slip send kro do
ReplyDeletedeekshabarai78@gmail.com into this email.
This comment has been removed by a blog administrator.
ReplyDeleteThis comment has been removed by a blog administrator.
ReplyDelete