rohidas

Hi I am Rohidas lande.I have teaching in C.D.jain college of commerce Shrirampur .I have Nine year in teaching Experience to teach various programming langauge,script languages,databases like Java,C,C++,php,python,html,css,javascript,mysql,oracle.

php_asignment4

Savitribai Phule Pune University S. Y. B. B. A. (C. A.) Semester-III (CBCS 2019 Pattern) CA-306: Lab Book Credits-03 Assignment 4:Functions, Class, and Object PHP ASSIGNMENT
Sr.NoAssignment name
Set-A
1
Write a PHP script to calculate x^y using a function. Plz Click on Question to see Answer

<html> <body bgcolor="red"> <form action=" " method="post"> <label for="">A : </label> <input type="number" name=a><br> <label for="">B : </label> <input type="number" name=b class=”> <br><br>      <input type="submit" value="Submit" class="btn btn-primary">                <input type="reset" value="Reset" class="btn btn-danger"> </form> <?php if(isset($_POST['a']) && isset($_POST['b'])) { $a = $_POST['a']; $b = $_POST['b']; echo"OUTPUT :<br> Calculated power is : " .(pow($a,$b)); } ?>


2
Write a PHP script to define a function EvenOdd,which will display even and odd numbers between 1 to 50. Plz Click on Question to see Answer

<?php $i=0; echo"Even Numbers : "; function evenodd($i) { for ($i=2; $i<=50; $i+=2) { echo $i." ";} echo"<br>Odd Numbers : "; for ($i=1; $i<=49; $i+=2) { echo $i." ";}} evenodd($i); ?>


3
Write a PHP script to define function Maximum, which will accept 3 numbers as parameters and retuns a maximum of 3 numbers. Plz Click on Question to see Answer

<html> <body> <form method="post" action="#"> enter number 1:<input type="text" name="t1"><br> enter number 2:<input type="text" name="t2"><br> enter number 3:<input type="text" name="t3"><br> <input type="submit" value="maximum"> </form> </body> </html> <?php function check($n1,$n2,$n3) { if($n1>$n2 && $n1>$n3) echo"first position $n1 is maximum number"; if($n2>$n3 && $n2>$n1) echo"second position $n2 is maximum number"; if($n3>$n2 && $n3>$n1) echo"third position $n3 is maximum number"; } $n1=$_POST["t1"]; $n2=$_POST["t2"]; $n3=$_POST["t3"]; check($n1,$n2,$n3); ?>


4
Write a PHP script to swap two numbers using a function (Use Call by value and Call by reference) Plz Click on Question to see Answer

<html> <body> <form method="post" action="#"> enter value a:<input type="text" name="t1"><br> enter value b:<input type="text" name="t2"><br><br> <input type="submit" value="swap"> </form> </body> </html> <?php function cvswap($a,$b) { $temp=$a; $a=$b; $b=$temp; echo"<br>after swapping by call by value a=$a and b=$b"; } function crswap(&$a,&$b) { $temp=$a; $a=$b; $b=$temp; echo"<br>after swapping by call by reference a=$a and b=$b"; } $a=$_POST["t1"]; $b=$_POST["t2"]; echo"<br>before swapping a=$a and b=$b"; cvswap($a,$b); crswap($a,$b) ?>


Set-B
1
Write a PHP Script to create a class Fruit that contains data members as Name, Color and Price. Write a member function to accept and display details of Fruit Plz Click on Question to see Answer

<?php class Fruit { public $name; public $color; public $price; function __construct($name,$color,$price) { $this->name = $name; $this->color = $color; $this->price = $price; } function get_name() { echo $this->name ." ". $this->color ." ".$this->price; } } $apple = new Fruit("Apple","Red","20"); $mango = new Fruit("mango","yellow","40"); $orange = new Fruit("orange","orange","30"); echo"<br>".$apple->get_name(); echo"<br>".$mango->get_name(); echo"<br>".$orange->get_name(); ?>


2
Write a PHP Script to create a class Student that contains data membersas Roll_Number,Stud_Name,and Percentage. Write member functions to accept Student information. Plz Click on Question to see Answer

<?php class student { public $Roll_Number; public $Stud_Name; public $Percentage; function __construct($Roll_Number,$Stud_Name,$Percentage) { $this->Roll_Number = $Roll_Number; $this->Stud_Name = $Stud_Name; $this->Percentage = $Percentage; } function get_name() { echo $this->Roll_Number ." ". $this->Stud_Name ." ".$this->Percentage; } } $s1 = new student("215101","rahul","78%"); $s2 = new student("215102","suresh","83%"); $s3 = new student("215103","gaurav","92%"); echo"<br>".$s1->get_name(); echo"<br>".$s2->get_name(); echo"<br>".$s3->get_name(); ?>


3
Write a PHP Script to create a class Book(Book_id,Book_name, Publication, Author, Book_price). Write a member function to accept and display Book details. Plz Click on Question to see Answer

<?php class Book { public $Book_id; public $Book_name; public $Publication; public $Author; public $Book_price; function __construct($Book_id, $Book_name, $Publication,$Author,$Book_price) { $this->Book_id = $Book_id; $this->Book_name = $Book_name; $this->Publication = $Publication; $this->Author = $Author; $this->Book_price = $Book_price; } function display() { echo $this->Book_id ." ".$this->Book_name ." ". $this->Publication. " ".$this->Author." ".$this->Book_price; } } $b1 = new Book("1. |","data structure |","Mcgraw Publication |","Lipschute |","217.00 |"); $b2 = new Book("2. |","DOS Guide |","PHI Publication |","Nortron |","175.00 |"); $b3 = new Book("3. |","turbo C++ |","Galgotia Publication |","Robart Lefore |","270.00 |"); echo"<table border=1><tr><td>"; echo"<br>".$b1->display(); echo"</td></tr><tr><td>"; echo"<br>".$b2->display(); echo"</td></tr><tr><td>"; echo"<br>".$b3->display(); echo"</td></tr>"; ?>


Set-C
1
Write a PHP script to define a function “DisplayDay”,which will display the day of the current date Plz Click on Question to see Answer

<?php function DisplayDay() { $today = date("D j"); echo $today; } DisplayDay(); ?>


2
Write a PHP script to perform arithmetic operations on two numbers.Write a PHP function to display the result. (Use the concept of function and default parameters) Plz Click on Question to see Answer

<html> <form action="#" method="post"> <label for="">A: </label> <input type="text" name="a" > <label for="">B : </label> <input type="text" name="b" ><br><br> <input type="submit" value="Submit"> </form> </html> <?php $a = $_POST['a']; $b = $_POST['b']; function add($num1, $num2=5) { $sum=$num1+$num2; echo "The Addition is : $sum"; } function sub($num1, $num2=5) { $sum=$num1-$num2; echo "The Subtraction is : $sum"; } function mul($num1, $num2=5) { $sum=$num1*$num2; echo "The Multiplication is : $sum"; } function div($num1, $num2=5) { $sum=$num1/$num2; echo "The Division is : $sum"; } add($a,$b) ; echo "<br>"; sub($a,$b) ; echo "<br>"; mul($a,$b) ; echo "<br>"; div($a,$b); ?>


Post a Comment

0 Comments