I wrote this basic calculator class using php.It will only execute the basic arithmetics operations so any suggestion for new functions add and improvements will be accepted. Thank you.
<?php
class Calculator{
public $x , $y , $z;
public function __construct($x,$y,$z){
$this->x = $x;
$this->y = $y;
$this->z = $z;
}
public function calc(){
try{
if($this->x != 0 && $this->z != 0){
switch($this->y){
case '+':
return ($this->x + $this->z);
break;
case '-':
return ($this->x - $this->z);
break;
case '/':
return ($this->x / $this->z);
break;
case '*':
return ($this->x * $this->z);
break;
}
} else {
throw new Exception('Operations with 0 not alloewd!');
}
}
catch(Exception $e){
return $e->getMessage();
}
}
}
?>