Advertisement
sanjiisan

Untitled

Apr 10th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. Napisz klasę Kalkulator(Calculator) w której będą atrybuty:
  2.  
  3. $firstElement
  4. $secondElement
  5. $oparations = [];
  6. $initializationDate;
  7.  
  8.  
  9. -----------
  10. Metody:
  11. makeOperation - Wykonuje oparacje na liczbach w argumentach. Po wykonaniu operacji dodajemy do tablicy z operacjami wpis na zasadzie: '1 + 6 = 7'
  12. Atrybuty first i second element były ustawiane na te z argumentów
  13.  
  14. Dostępne operacje:
  15. Mnożenie,
  16. Dzielenie,
  17. Dodawanie
  18. Odejmowanie,
  19. Potęgowanie(^)
  20.  
  21. makeOperation($firstElement, $secondElement, $operator){
  22. switch($operator){
  23. case: '*'{
  24. return $firstelement * $secondElement;
  25. }
  26. }
  27. }
  28.  
  29. Metoda getOperations:
  30.  
  31. Operacja 1: '1 + 5 =6'
  32. Operacja 2: '2 * 6 = 12'
  33. Operacja 3: '3 - 2 = 1'....
  34. /////
  35.  
  36. Klasa ma implementować konstruktor
  37. gdzie to atrybutu:
  38. $initializationDate ustawiamy aktualny 'timestamp
  39.  
  40. -------
  41.  
  42. $calculator = new Calculator();
  43.  
  44. $calculator->makeOparation(6, 7, '*');
  45. $calculator->makeOparation(6, 2, '/');
  46. $calculator->makeOparation(10, 2, '^');
  47.  
  48. $calculator->getOperations();
  49. /*
  50. Operacja 1: '6 * 7 = 42'
  51. Operacja 2: '6 / 2 = 3'
  52. Operacja 3: '10 ^ 2 = 100'
  53. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement