Advertisement
Crying2812

Untitled

Nov 30th, 2015
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.49 KB | None | 0 0
  1. <?php
  2.     /**
  3.     *
  4.     */
  5.     class Calculator
  6.     {
  7.         var $so_thu_nhat;
  8.         var $so_thu_hai;
  9.         var $result = 0;
  10.         function phepTinh($phuongThuc,$so_thu_nhat,$so_thu_hai){
  11.             $this->so_thu_nhat  = (int)$so_thu_nhat;
  12.             $this->so_thu_hai = (int)$so_thu_hai;
  13.             $phuongThuc = '';
  14.             switch ($phuongThuc) {
  15.                 case '-':
  16.                     $result = $this->so_thu_nhat - $this->so_thu_hai;
  17.                     break;
  18.                 case '+':
  19.                     $result = $this->so_thu_nhat + $this->so_thu_hai;
  20.                     break;
  21.                 case '/':
  22.                     $result = $this->so_thu_nhat / $this->so_thu_hai;
  23.                     break;
  24.                 case '*':
  25.                     $result = $this->so_thu_nhat * $this->so_thu_hai;
  26.                 break;
  27.  
  28.                 default:
  29.                     $result = $this->so_thu_nhat + $this->so_thu_hai;
  30.                     break;
  31.             }
  32.             return $this->$result;
  33.         }
  34.  
  35.         function phepTinh2n($phuongThuc,$so_thu_hai){
  36.             $condition = 'Giả sử như đây là phép tính đã có số đầu tiên (kết quả từ phép tính trước) ';
  37.             if ($condition == true) {
  38.                 $this->so_thu_hai = (int)$so_thu_hai;
  39.                 $phuongThuc = '';
  40.                 switch ($phuongThuc) {
  41.                     case '-':
  42.                         $result = $this->result - $this->so_thu_hai;
  43.                         break;
  44.                     case '+':
  45.                         $result = $this->result + $this->so_thu_hai;
  46.                         break;
  47.                     case '/':
  48.                         $result = $this->result / $this->so_thu_hai;
  49.                         break;
  50.                     case '*':
  51.                         $result = $this->result * $this->so_thu_hai;
  52.                     break;
  53.  
  54.                     default:
  55.                         $result = $this->result + $this->so_thu_hai;
  56.                         break;
  57.                 }
  58.                 return $this->$result;
  59.             }
  60.         }  
  61.     }
  62.  ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement