1)Write
a Calculator class that can accept two values, then add them, subtract them,
multiply them together, or divide them on request. For example:
$calc = new Calculator( 3, 4 );
echo $calc- >add(); // Displays “7”
echo $calc- >multiply(); // Displays “12”
calculator.html
<HTML>
<BODY>
<FORM method=get
action="Calculate.php">
Enter first value: <INPUT type=text
name="a"><br>
Enter second value:<INPUT type=text
name="b"><br>
<INPUT type=submit>
</FORM>
</BODY>
</HTML>
calculate.php
<?php
class Calculate
{
public $a;
public $b;
function __construct($a,$b)
{
$this->a=$a;
$this->b=$b;
}
public function add()
{
$c=$this->a+$this->b;
echo"Addition = $c<br>";
}
public function subtract()
{
$c=$this->a-$this->b;
echo"Subtract = $c<br>";
}
public function multiply()
{
$c=$this->a*$this->b;
echo"Multiplication = $c<br>";
}
public function div()
{
$c=$this->a/$this->b;
echo"Division = $c";
}
}
$x=$_GET['a'];
$y=$_GET['b'];
$calc=new Calculate($x,$y);
$calc->add();
$calc->subtract();
$calc->multiply();
$calc->div();
?>
2)Create a login form with a username and password. Once the user logs in, thesecond form should be displayed to accept user details (name, city, phoneno).If the user doesn’t enter information within a specified time limit, expire hissession and give a warning otherwise Display Details($_SESSION).
log.php
<?php
session_start();
if(set_time_limit(20)) echo"Time Expired";
if(($_REQUEST['uname']=="archana")and($_REQUEST['pwd']=="archana"))
{
echo"<form method='post' action='display.php'>";
echo"<b>Roll No:</b><input type='text'
name='roll'<br><br>";
echo"<b>Name:</b><input type='text'
name='name'<br><br>";
echo"<b>City:</b><input type='text'
name='city'<br><br>";
echo"<input type='submit'
name='display'/></form>";
}
else
echo
"wrong information...<a href='log.html'>login.html</a>";
?>
log.html
<html>
<head>
<title>PHP sript</title>
</head>
<body>
<form
method="get" action="log.php">
<b>User Name:</b><input type="text"
name="uname"><br><br>
<b>Password:</b><input type="password"
name="pwd"><br><br>
<input
type="submit" value="login">
</form>
</body>
</html>
display.php
<?php
echo"RollNo:".$_REQUEST['roll']."<br>";
echo"Name:".$_REQUEST['name']."<br>";
echo"City:".$_REQUEST['city']."<br>";
?>