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)
student.html
<html>
<body>
<form method=get action="student.php">
Enter Roll No. <input type=text name="a"><br>
<input type=submit value=submit>
</form>
</body>
</html>
student.php
<?php
$a=$_GET['a'];
if(@ereg("^BC|A|S([1-3])([0-9][0-9][0-9])$",$a))
{
echo"Roll no = ".substr($a,3)."<br>";
$year=substr($a,2,1);
if($year=='1')
echo"Year = 1st <br>";
if($year=='2')
echo"Year = 2nd <br>";
if($year=='3')
echo"Year = 3rd <br>";
$fac=substr($a,0,2);
if($fac=='BA')
echo"Faculty = BA";
if($fac=='BC')
echo"Faculty = BCA";
if($fac=='BS')
echo"Faculty = B.Sc.";
}
else
{
echo"Invalid Roll No.";
}
?>
2)Define an interface
which has methods area(), volume(). Define constant PI. Create aclass cylinder
which implements this interface and calculate area and volume.(Use define())
<?php
define('PI','3.14');
interface Cyl
{
function area();
function volume();
}
class Cylinder implements Cyl
{
public $PI=3.14;
public $a;
public $r;
public $h;
function __construct($r,$h)
{
$this->r=$r;
$this->h=$h;
}
function area()
{
$this->a=2*$this->PI*($this->h*$this->r);
echo"Area = ".$this->a."<br>";
}
function volume()
{
$this->a=$this->PI*$this->r*$this->r*$this->h;
echo"Volume = ".$this->a."<br>";
}
}
$c=new Cylinder(5,5);
$c->area();
$c->volume();
?>