Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ODCZYT DANYCH
- <?php
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- class OdczytDanych{
- private $nazwaPliku;
- private $zbiory;
- public function getNazwaPliku() {return $this->nazwaPliku;}
- public function setNazwaPliku($nazwaPliku) {$this->nazwaPliku=$nazwaPliku;}
- public function getZbiory() {return $this->zbiory;}
- public function setZbiory($zbiory) {$this->zbiory=$zbiory;}
- public function odczytaj () {
- }
- public function odczytaj() {
- $zbiory = array(); // 1
- $zbior = array(); // 2
- $file = fopen($this->nazwaPliku, 'r'); // 3
- while (FALSE === feof($file)) { // 4
- $linia = fgets($file, 4096); // 4,1
- if ($linia === "\0")
- break; //krok 4,2
- else {
- $znaki = array(" ", "\t", "\r", "\n"); //4.3
- $nowyZnak = "";
- $linia = str_replace($znaki, $nowyZnak, $linia);
- }
- $pierwszy = substr($linia, 0, 1); //4.4
- $ostatni = substr($linia, -1); //4.4
- if ($pierwszy !== "{" || $ostatni !== "}") {
- break;}
- $linia = rtrim($linia, "}"); //4.5
- $linia = ltrim($linia, "{"); //4.5
- $zbior = explode(",", $linia); //4,6
- $zbiory[] = $zbior; //4.7
- }
- fclose($file); //5
- $this->zbiory = $zbiory;//6
- }
- }
- OPERACJE NA ZBIORACH
- <?php
- class OperacjeNaZbiorach {
- private $zbiory;
- private $wynik;
- public function getZbiory(){return $this->zbiory;}
- public function setZbiory($zbiory){$this->zbiory = $zbiory;}
- public function getWynik() {return $this->wynik;}
- public function suma()
- {
- $wynik = $this->zbiory[0];
- $ilosc = count($this->zbiory);
- for($i=1; $i<$ilosc; $i++)
- {
- $tablica = $this->zbiory[$i];
- $wynik=array_merge($wynik,$tablica);
- $wynik= array_unique($wynik);
- }
- $this->wynik =$wynik;
- }
- public function roznica(){}
- public function iloczyn(){}
- }
- PROGRAM JAO
- <?php
- include_once "./OperacjeNaZbiorach.php";
- include_once "./OdczytDanych.php";
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- /**
- * Description of ProgramJAO
- *
- * @author student
- */
- class ProgramJAO {
- public $wynik;
- public function main() {
- $zbiory = array(); // 1
- $zbior = array(); // 2
- $odczytDanych = new OdczytDanych(); //punkt 1
- $odczytDanych->setNazwaPliku("dane.txt"); //punkt 2
- $odczytDanych->odczytaj(); //punkt 3
- $zbiory = $odczytDanych->getZbiory(); //punkt 4
- print_r($zbiory);
- $operacjeNaZbiorach = new OperacjeNaZbiorach(); //punkt 5
- $operacjeNaZbiorach->setZbiory($zbiory); //punkt 6
- $operacjeNaZbiorach->suma(); //punkt 7
- $operacjeNaZbiorach ->getWynik(); //punkt 8
- $this->wynik=$operacjeNaZbiorach->getWynik();
- }
- }
- INDEX.PHP
- <?php
- require_once "./ProgramJAO.php";
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- $program = new ProgramJAO();
- $program->main();
- print_r($program->wynik);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement