1. Write a PHP script that utilizes the concept of Classes and Objects in creati
ID: 3890862 • Letter: 1
Question
1. Write a PHP script that utilizes the concept of Classes and Objects in creating a concrete solution. Create a student class with information about the student. Write a display function to show all the student information. Create multiple objects from the student class and display their information. 2. Write a PHP script that utilizes the concept of Classes and Objects in creating a concrete solution. Create a Math class with at-least four math functions (add, subtract etc. etc). Create multiple objects of from the class and utilize all the math functions. Use constructors to allocate default values Write a PHP script that utilizes the concept of Classes and Objects in creating a concrete solution. Create a student class with information about the student. Write a display function to show all the student information. Create multiple objects from the student class and display their information. 1. 2 Write a PHP script that utilizes the concept of Classes and Objects in creating a concrete solution. Create a Math class with at-least four math functions (add, subtract etc. etc). Create multiple objects of from the class and utilize all the math functions. Use constructors to allocate default values. Also, submit the php files in the Assignment 4 folder under Dropbox. Purpose: Comprehend and design a solution to demonstrate your understanding of how a programs are applied in real life scenario. Understand class-object relationship and implement them in a solution. Assignments 4.1 Points Assignments 4.2 PointsExplanation / Answer
student.php
<?php
class Student //create class
{
var $sname; // student name
var $sid; // student id
var $sclass; // student class
var $sbranch; //student branch
function Student($name, $id, $class,$branch) //constructor for class Student
{
//varible initialization
$this->sname=$name;
$this->sid=$id;
$this->sclass=$class;
$this->sbranch=$branch;
}
function display() //function defination for display varibles
{
echo "Student Name : ".$this->sname."<br>"; //display intialized student information
echo $this->sname." ID : ".$this->sid."<br>";
echo $this->sname." Class : ".$this->sclass."<br>";
echo $this->sname." Branch : ".$this->sbranch."<br><br>";
}
}
//object creation and display
$obj1=new Student("Ashok1","11111","GF1","CSE");
$obj1->display();
//object creation and display
$obj2=new Student("Ashok2","22222","GF2","ECE");
$obj2->display();
//object creation and display
$obj3=new Student("Ashok3","33333","GF3","MECH");
$obj3->display();
?>
Output :
Student Name : Ashok1
Ashok1 ID : 11111
Ashok1 Class : GF1
Ashok1 Branch : CSE
Student Name : Ashok2
Ashok2 ID : 22222
Ashok2 Class : GF2
Ashok2 Branch : ECE
Student Name : Ashok3
Ashok3 ID : 33333
Ashok3 Class : GF3
Ashok3 Branch : MECH
Math.php :
<?php
class Math //create class
{
var $a; // varible a
var $b; // varible b
var $c; // varible c
function Math($a1, $b1) //constructor for class Math
{
//varible initialization
$this->a=$a1;
$this->b=$b1;
}
function add() //function defination for addition of varibles
{
$this->c=$this->a + $this->b; // add a,b
echo "Addition of ".$this->a.",".$this->b." is ".$this->c."<br>"; //display add result
}
function sub() //function defination for substraction of varibles
{
$this->c=$this->a - $this->b; // sub a,b
echo "substraction of ".$this->a.",".$this->b." is ".$this->c."<br>"; //display sub result
}
function mul() //function defination for substration of varibles
{
$this->c=$this->a * $this->b; // mul a,b
echo "Multiplication of ".$this->a.",".$this->b." is ".$this->c."<br>"; //display mul result
}
function div() //function defination for substration of varibles
{
$this->c=$this->a / $this->b; // div a,b
echo "Division of ".$this->a.",".$this->b." is ".$this->c."<br>"; //display div result
}
}
//object creation and display
$obj1=new Math(10,20);
$obj1->add();
$obj1->sub();
$obj1->mul();
$obj1->div();
?>
Output :
Addition of 10,20 is 30
substraction of 10,20 is -10
Multiplication of 10,20 is 200
Division of 10,20 is 0.5
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.