Advanced Web Technology
Slip2
Q.1) A college has given roll number to each student, The roll number is six digit number where first two digits are faculty(B.Sc., BCA, BA) third digit is year (Ist(1), IInd(2) and IIIrd(3)) and last three digit are actual number. Write PHP script to accept a number and print faculty, year and roll number of student.(e.g Rollno=BC1004,faculty=BCA, year=1st,rollno=004) [15]
Solution
<html>
<body>
<form action="Q2.php" method='get'>
<table>
<tr>
<td>Enter Your Roll No. </td>
<td><input type=text name=roll_no placeholder="ex. 112001">
<input type=Submit value="Submit"></td>
</tr>
<tr>
<td></td><td><font color="red" size="2">format of Roll No: first two
digits is 11 for B.sc., 12 for Bcom, 13 for BA<br>third digit 1/2/3 for
respective year<br>last three are for actual roll no.</font></td>
</tr>
</table>
</form>
</body>
</html>
Php file :
<?php
$roll_no=$_GET['roll_no'];
echo "Your Roll Number Is :$roll_no<br>";
$fac=substr($roll_no,0,2);
if($fac==11)
echo "Faculty is B.Sc<br>";
else if($fac==12)
echo "Faculty is Bcom<br>";
else if($fac==13)
echo "Faculty is BA<br>";
$year=substr($roll_no,2,1);
if($year==1)
echo "Year is First Year<br>";
else if($year==2)
echo "Year is Second Year<br>";
else if($year==3)
echo "Year is Third Year<br>";
echo "Your Roll No. is".substr($roll_no,3)."<br>";
?>
Q.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()) [25]
Solution
html file :
<html>
<body bgcolor="gold">
<center>
<h2> Calculate area and value of cylinder</h2>
<form action="slip_2.php" method="GET">
<h3> Enter radius : <input type=text name=r><br> </h3>
<h3> Enter height : <input type=text name=h><br><br> </h3>
<input type=submit value=submit name=Show>
<input type=reset value=Reset name=Reset>
</form>
</center>
</body>
<html>
Php file :
<?php
$r = $_GET['r'];
$h = $_GET['h'];
define('PI','3.14');
interface cal
{
function area($r,$h);
function vol($r,$h);
}
class cylinder implements cal
{
function area($r,$h)
{
$area = 2*PI*$r*($r+$h);
echo "<h3>The area of cylinder is :$area</h3>";
}
function vol($r,$h)
{
$vol = PI*$r*$r*$h;
echo "<h3>The volume of cylinder is :$vol</h3>";
}
$c = new cylinder;
$c->area($r,$h);
$c->vol($r,$h);
?>
Tags:
Advanced Web Technology