PHP Practical Slip 18 Q.B

Write a PHP Script to create a class Student that contains data members as
Roll_Number, Stud_Name, and Percentage. Write member functions to accept Student
information

<?php

class Student {

    public $Roll_Number;
    public $Stud_Name;
    public $Percentage;

    // Member Function to accept student information
    public function accept($roll, $name, $per) {
        $this->Roll_Number = $roll;
        $this->Stud_Name = $name;
        $this->Percentage = $per;
    }

    // Member Function to display student information
    public function display() {
        echo "<h3>Student Information</h3>";
        echo "Roll Number: " . $this->Roll_Number . "<br>";
        echo "Student Name: " . $this->Stud_Name . "<br>";
        echo "Percentage: " . $this->Percentage . "%<br>";
    }
}

// Create object of Student class
$stud1 = new Student();

// Accept student data
$stud1->accept(101, "Rahul Sharma", 85.6);

// Display student data
$stud1->display();

?>
Spread the love

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top