Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Calculator {
- public $number1;
- public $number2;
- public $op_type; // operation type . + . - . * . /
- function set_value($n1,$n2)
- {
- $this -> number1 = $n1;
- $this -> number2 = $n2;
- }
- function setop($op) // set operation
- {
- $this -> op_type = $op;
- }
- function Calculate()
- {
- switch ($this -> op_type)
- {
- case '+';
- echo $this -> number1 + $this -> number2;
- break;
- case '-';
- echo $this -> number1 - $this -> number2;
- break;
- case '*';
- echo $this -> number1 * $this -> number2;
- break;
- case '/';
- if ($this -> number2 == 0)
- echo " Div by zer0";
- else
- echo $this -> number1 / $this -> number2;
- break;
- }
- }
- }
- $v = new Calculator();
- $v->set_value(10,5);
- $v->setop('/');
- $v->Calculate();
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement