<?php require_once 'product-oop.php'; $name = new product3(); echo $name->type; ?> <br> <?php require_once 'product-oop.php'; $name = new product4(); //echo $name -> type; // kaj korbena. echo $name->getProductType(); // kaj korbe. ?> <br> <?php require_once 'calculator-oop.php'; $calc = new calculator(); $calc->add(5 + 10); $calc->add(20); $calc->subtract(5); // output will be : 35-5 = 30 echo $calc->getTotal(); ?>
<?php require_once "calculator.php"; $calculator = new calculator(); $calculator->add(1, 2); $calculator->showresult();
public function __construct($num1, $num2) { $this->num1 = $num1; $this->num2 = $num2; } public function add() { return $this->num1 + $this->num2; } public function subtract() { return $this->num1 - $this->num2; } public function multiply() { return $this->num1 * $this->num2; } public function divide() { return $this->num1 / $this->num2; } } // end of class $calc = new calculator(3, 4); echo "<p>3 + 4 = " . $calc->add() . "</p>"; $calc = new calculator(15, 12); echo "<p>15 - 12 = " . $calc->subtract() . "</p>"; $calc = new calculator(20, 2); echo "<p> 20 * 2 = " . $calc->multiply() . "</p>"; $calc = new calculator(20, 8); echo "<p> 20 / 2 = " . $calc->divide() . "</p>";
public $a; public $b; public $c; function __construct($num1, $num2) { $this->a = $num1; $this->b = $num2; } function add() { $this->c = $this->a + $this->b; echo $this->c; } function substract() { $this->c = $this->a - $this->b; echo $this->c; } } $num1 = $_POST["num1"]; $num2 = $_POST["num2"]; $p = new calculator($num1, $num2); $oper = $_POST["oper"]; switch ($oper) { case "+": $p->add(); break; case "-": $p->substract(); break; }
<?php require 'class.calculator.php'; $calculator = new calculator(); $calculator->num1 = 10.5; $calculator->num2 = 4.5; echo "Welcome to our simple calculator class"; echo "<br>"; echo "The addition between " . $calculator->num1 . " and " . $calculator->num2 . " is " . $calculator->add(); echo "<br>"; echo "The subtraction between " . $calculator->num1 . " and " . $calculator->num2 . " is " . $calculator->subtract(); echo "<br>"; echo "The multiplication between " . $calculator->num1 . " and " . $calculator->num2 . " is " . $calculator->multiply(); echo "<br>"; echo "The division between " . $calculator->num1 . " and " . $calculator->num2 . " is " . $calculator->divide();
<?php require_once './calculator.php'; $obj = new calculator(); echo '<pre>'; print_r($_POST); $first = $_POST['first-number']; $second = $_POST['second-number']; $button = $_POST['btn']; if ($button == 'add') { $add = $obj->add($first, $second); } if ($button == 'sub') { $add = $obj->sub($first, $second); } if ($button == 'mul') { $add = $obj->mul($first, $second); } if ($button == 'div') { $add = $obj->div($first, $second); } if ($button == 'mod') { $add = $obj->mod($first, $second); } ?> <html> <head> <title>Calculator</title> </head>