Rakibul_Ahasan

Calculator(using include/require)

Jan 28th, 2021
632
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Son.php file
  2. <?php
  3.  
  4.   require 'Father.php';
  5.   //include 'Father.php';
  6.  
  7.   class ChildClass extends ParentClass
  8.   {
  9.       private $sum,$sub,$mult,$div;
  10.  
  11.     function __construct($num1,$num2){
  12.         $this->sum = $this->add($num1,$num2);
  13.         $this->sub = $this->subtract($num1,$num2);
  14.         $this->mult = $this->multiply($num1,$num2);
  15.         $this->div = $this->divide($num1,$num2);
  16.     }
  17.  
  18.     public function Display(){
  19.        echo 'Summation is: '. $this->sum.'<br>';
  20.        echo 'Subtract is: '. $this->sub.'<br>';
  21.        echo 'Multiply is: '. $this->mult.'<br>';
  22.        echo 'Division is: '. $this->div.'<br>';
  23.     }
  24.  
  25.    }
  26.  
  27.    $myObject = new ChildClass(20,10);
  28.  
  29.    echo $myObject->Display();
  30. ?>
  31.  
  32. //Father.php file
  33. <?php
  34.   class ParentClass
  35.    {
  36.       /*private $num1;
  37.       private $num2;*/
  38.  
  39.       protected function add($num1,$num2){
  40.          /*$this->num1 = $num1;
  41.          $this->num2 = $num2;*/
  42.          return $num1 + $num2;
  43.       }
  44.  
  45.       protected function subtract($num1,$num2){
  46.         /* $this->num1 = $num1;
  47.          $this->num2 = $num2;*/
  48.          return $num1 - $num2;
  49.       }
  50.  
  51.       protected function multiply($num1,$num2){
  52.         /* $this->num1 = $num1;
  53.          $this->num2 = $num2;*/
  54.          return $num1 * $num2;
  55.       }
  56.  
  57.       protected function divide($num1,$num2){
  58.          /*$this->num1 = $num1;
  59.          $this->num2 = $num2;*/
  60.          return $num1 / $num2;
  61.       }
  62.      
  63.    }
  64. ?>
RAW Paste Data