Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Napisz klasę Kalkulator(Calculator) w której będą atrybuty:
- $firstElement
- $secondElement
- $oparations = [];
- $initializationDate;
- -----------
- Metody:
- makeOperation - Wykonuje oparacje na liczbach w argumentach. Po wykonaniu operacji dodajemy do tablicy z operacjami wpis na zasadzie: '1 + 6 = 7'
- Atrybuty first i second element były ustawiane na te z argumentów
- Dostępne operacje:
- Mnożenie,
- Dzielenie,
- Dodawanie
- Odejmowanie,
- Potęgowanie(^)
- makeOperation($firstElement, $secondElement, $operator){
- switch($operator){
- case: '*'{
- return $firstelement * $secondElement;
- }
- }
- }
- Metoda getOperations:
- Operacja 1: '1 + 5 =6'
- Operacja 2: '2 * 6 = 12'
- Operacja 3: '3 - 2 = 1'....
- /////
- Klasa ma implementować konstruktor
- gdzie to atrybutu:
- $initializationDate ustawiamy aktualny 'timestamp
- -------
- $calculator = new Calculator();
- $calculator->makeOparation(6, 7, '*');
- $calculator->makeOparation(6, 2, '/');
- $calculator->makeOparation(10, 2, '^');
- $calculator->getOperations();
- /*
- Operacja 1: '6 * 7 = 42'
- Operacja 2: '6 / 2 = 3'
- Operacja 3: '10 ^ 2 = 100'
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement