Professional Documents
Culture Documents
Oops Programs
Oops Programs
/
Name:Vivekkumar Yadav ROLL NO:: B 79
Class::TYBSc( Computer Science) Batch::F
function Square($s)
{
$this->s=$s;
}
function area()
{
$this->area=$this->s*$this->s;
echo"\n Area of square is : $this->area";
}
}
class Circle implements Shape
{
var $r,$area;
const PI=3.14;
function Circle($r)
{
$this->r=$r;
}
function area()
{
$this->area=(Circle::PI)*$this->r*$this->r;
echo"\nArea of Circle is : $this->area";
}
}
$obj1=new Rectangle(5,4);
$obj1->area();
$obj2=new Square(4);
$obj2->area();
$obj3=new Circle(5);
$obj3->area();
?>
/
*********************************OUTPUT******************************
[Akshay@localhost Ass4]$ php ex4sb1.php
Area of Rectangle is : 20
Area of square is : 16
Area of Circle is : 78.5
/
Name:Vivekkumar Yadav ROLL NO:: B 79
Class::TYBSc( Computer Science) Batch::F
function saving_account($ano,$cname,$balance,$min_amount)
{
$this->account($ano,$cname);
$this->balance=$balance;
$this->min_amount=$min_amount;
}
function display()
{
echo"\n Account No : $this->ano";
echo"\n Account Type : Saving Account ";
echo"\n Customer Name : $this->cname";
echo"\n Account Balance : $this->balance";
}
function getbalance()
{
return $this->balance;
}
function withdraw($amount)
{
$bal=$this->getbalance();
$bal=$bal-$amount;
function deposit($amount)
{
$this->balance +=$amount;
}
}
class current_account extends account
{
var $balance,$min_amount;
function current_account($ano,$cname,$balance,$min_amount)
{
$this->account($ano,$cname);
$this->balance=$balance;
$this->min_amount=$min_amount;
}
function display()
{
echo"\n Account No : $this->ano";
echo"\n Account Type : Current Account ";
echo"\n Customer Name : $this->cname";
echo"\n Account Balance : $this->balance";
}
function getbalance()
{
return $this->balance;
}
function withdraw($amount)
{
$bal=$this->getbalance();
$bal=$bal-$amount;
echo"\n Type (S) for Saving Account or (C) for Current account : ";
$account_type=fgets(STDIN);
if($account_type=="S\n" || $account_type=="s\n")
{
$class_name="saving_account";
}
else
{
$class_name="current_account";
}
do
{
echo"\n************************************MENU for $class_name ************************\
n";
echo"\n1.Create Account\n";
echo"\n2.Deposit Amount into Account\n";
echo"\n3.Withdrawl Amount from Account\n";
echo"\n4.Exit\n";
echo"\nEnter your choice: ";
$ch=fgets(STDIN);
switch($ch)
{
case 1 :
echo"\n Enter Account No of Customer : ";
$ano=fgets(STDIN);
echo"\n Enter Name of Customer : ";
$cname=fgets(STDIN);
echo"\n Enter Balance : ";
$balance=fgets(STDIN);
$s_acc=new $class_name($ano,$cname,$balance,500);
echo"\n--------------------------------------------------------------------------------\n";
$s_acc->display();
echo"\n--------------------------------------------------------------------------------\n";
break;
case 2 :
echo"\n Enter Deposit amount : ";
$amt=fgets(STDIN);
$s_acc->deposit($amt);
echo"\n You deposited RS $amt in your Account \n";
echo"\n Current Balance of Account is ". $s_acc->getbalance() ;
break;
case 3 :
echo"\n Enter Withdrawl amount : ";
$amt=fgets(STDIN);
$s_acc->withdraw($amt);
// echo"\n You have withdrawl Rs $amt from your account \n";
echo"\n Current Balance of Account is ".$s_acc->getbalance();
break;
break;
}
}
while($ch!=4);
?>
/*
*********************************OUTPUT********************************
[Akshay@localhost Ass4]$ php ex4sb2.php
1.Create Account
4.Exit
--------------------------------------------------------------------------------
Account No : 1546458
--------------------------------------------------------------------------------
1.Create Account
1.Create Account
4.Exit
1.Create Account
4.Exit
1.Create Account
4.Exit
--------------------------------------------------------------------------------
Account No : 5464465
--------------------------------------------------------------------------------
1.Create Account
4.Exit
1.Create Account
4.Exit
1.Create Account
4.Exit
1.Create Account
4.Exit
$ele=array_pop($this->stk);
return $ele;
}
function display()
{
echo"\nStack is :";
/*for($i=count($this->stk)-1;$i>=0;$i--)
echo"\n".$this->stk[$i];*/
print_r($this->stk);
}
}
do
{
echo"\n***************MENU*********************\n";
echo"\n1.Insert an element into stack \n";
echo"\n2.Delete an element from stack \n";
echo"\n3.Display the contents of stack\n";
echo"\n4.Exit\n";
echo"\nEnter your choice : ";
$ch=fgets(STDIN);
$obj=new Stack();
switch($ch)
{
case 1 :echo"\nEnter the element into stack : ";
$ele=fgets(STDIN);
$e=substr($ele,0,strlen($ele)-1);
// $e=explode(',',$ele);
$obj->push($e);
break;
case 2 : $ele=$obj->pop();
echo"\n The deleted element from a stack is $ele";
break;
case 3 :$obj->display();
break;
case 4 : die("\nYou exited..........");
break;
}
while($ch!=4);
?>
/*
********************************OUTPUT***********************************
[Akshay@localhost Ass4]$ php ex4sc1.php
/*
SetC1
*/
***************MENU*********************
4.Exit
***************MENU*********************
4.Exit
4.Exit
***************MENU*********************
4.Exit
Enter your choice : 1
***************MENU*********************
4.Exit
Stack is :Array
(
[0] => 10
[1] => 20
[2] => 30
[3] => 40
)
***************MENU*********************
4.Exit
4.Exit
Stack is :Array
(
[0] => 10
[1] => 20
[2] => 30
)
***************MENU*********************
4.Exit
You exited.........
Name:Vivekkumar Yadav ROLL NO:: B 79
Class::TYBSc( Computer Science) Batch::F
function display()
{
for($i=0;$i<count($this->pcode);$i++)
{
echo"\nPlayer Name :". $this->pname[$i] ;
echo"\nPlayer Code :". $this->pcode[$i] ;
echo"\nInnings Played :". $this->innings[$i] ;
echo"\nTotal Runs :". $this->runs[$i] ;
echo"\nNumber of Times Not Out :". $this->notout[$i] ;
}
}
function sort_runs()
{
array_multisort($this->runs,$this->pcode,$this->innings,$this->pname,$this->notout);
$this->display();
}
function __call($method,$arguments)
{
if($method=="average")
{
if(count($arguments)==0)
{
$avg=array();
for($i=0;$i<count($this->pname);$i++)
{
$avg[$i]=$this->runs[$i]/$this->innings[$i];
}
return($avg);
}
if(count($arguments)==1)
{
for($i=0;$i<count($this->pname);$i++)
{
if($this->pcode[$i]==$arguments[0])
{
return($this->runs[$i]/$this->innings[$i]);
}
}
}
}
}
}
do
{
echo"\n********************************MENU************************************\n";
echo"\n1.Accept Details of Players \n";
echo"\n2.Display Average Runs of a Single Player \n";
echo"\n3.Display Average Runs of All Players \n";
echo"\n4.Display List Of players in Sorted Order \n ";
echo"\n5.Exit\n";
echo"\n Enter your choice : ";
$ch=fgets(STDIN);
switch($ch)
{
case 1 :
echo"\n Enter Player Code : ";
$c1=fgets(STDIN);
$c=substr($c1,0,strlen($c1)-1);
$obj=new player($c,$inn,$name,$runs,$notout);
echo"\n+++++++++++++++++++++++++++++Player Details are++++++++++++
+++++++++++++ \n";
$obj->display();
break;
case 2 :
echo"\nEnter Player Code : ";
$c1=fgets(STDIN);
$c=substr($c1,0,strlen($c1)-1);
echo"\n Average Runs of player of Player Code $c1 is " .$obj->average($c);
break;
case 3 :
echo"\n Average Runs of All players are \n";
$b=$obj->average();
print_r($b);
break;
case 4 :
echo"\nPlayer Details in sorted order is :\n";
$obj->sort_runs();
echo"\n----------------------------------------------------------------------\n";
break;
case 5 :die("\n You Exited-------------\n");
}
}while($ch!=5);
?>
OUTPUT-
********************************MENU************************************
5.Exit
Innings Played : 21
5.Exit
Innings Played : 28
5.Exit
********************************MENU************************************
5.Exit
5.Exit
********************************MENU************************************
5.Exit