Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class problem {
- private $operator;
- private $num1;
- private $num2;
- private $solution;
- public function __construct($operator, $num1, $num2) {
- $this->operator = $operator;
- $this->num1 = $num1;
- $this->num2 = $num2;
- }
- function problemSolve() {
- switch ($this->operator){
- case '+':
- $this->solution = $this->num1 + $this->num2;
- break;
- case '-':
- $this->solution = $this->num1 - $this->num2;
- break;
- case '/':
- $this->solution = $this->num1 / $this->num2;
- break;
- case '*':
- $this->solution = $this->num1 * $this->num2;
- break;
- case 'sqrt':
- $this->solution = sqrt($this->num1);
- break;
- default:
- echo "Error, input not recognised.";
- break;
- }
- }
- function solutionOutput() {
- echo "$this->solution";
- }
- }
- $calc = new problem('put_operator_here', first_number_here, second_number_here);
- $calc->problemSolve();
- $calc->solutionOutput();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement