Advertisement
poor_fool_mloody

Untitled

Oct 25th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.94 KB | None | 0 0
  1.  
  2. ODCZYT DANYCH
  3. <?php
  4.  
  5. /*
  6. * To change this license header, choose License Headers in Project Properties.
  7. * To change this template file, choose Tools | Templates
  8. * and open the template in the editor.
  9. */
  10.  
  11. class OdczytDanych{
  12. private $nazwaPliku;
  13. private $zbiory;
  14.  
  15.  
  16.  
  17. public function getNazwaPliku() {return $this->nazwaPliku;}
  18. public function setNazwaPliku($nazwaPliku) {$this->nazwaPliku=$nazwaPliku;}
  19. public function getZbiory() {return $this->zbiory;}
  20. public function setZbiory($zbiory) {$this->zbiory=$zbiory;}
  21. public function odczytaj () {
  22.  
  23. }
  24. public function odczytaj() {
  25.  
  26. $zbiory = array(); // 1
  27. $zbior = array(); // 2
  28. $file = fopen($this->nazwaPliku, 'r'); // 3
  29.  
  30. while (FALSE === feof($file)) { // 4
  31. $linia = fgets($file, 4096); // 4,1
  32. if ($linia === "\0")
  33. break; //krok 4,2
  34. else {
  35. $znaki = array(" ", "\t", "\r", "\n"); //4.3
  36. $nowyZnak = "";
  37. $linia = str_replace($znaki, $nowyZnak, $linia);
  38. }
  39.  
  40. $pierwszy = substr($linia, 0, 1); //4.4
  41. $ostatni = substr($linia, -1); //4.4
  42. if ($pierwszy !== "{" || $ostatni !== "}") {
  43. break;}
  44.  
  45. $linia = rtrim($linia, "}"); //4.5
  46. $linia = ltrim($linia, "{"); //4.5
  47.  
  48. $zbior = explode(",", $linia); //4,6
  49. $zbiory[] = $zbior; //4.7
  50. }
  51. fclose($file); //5
  52. $this->zbiory = $zbiory;//6
  53.  
  54. }
  55.  
  56.  
  57.  
  58. }
  59.  
  60. OPERACJE NA ZBIORACH
  61. <?php
  62.  
  63. class OperacjeNaZbiorach {
  64.  
  65. private $zbiory;
  66.  
  67. private $wynik;
  68.  
  69.  
  70.  
  71. public function getZbiory(){return $this->zbiory;}
  72.  
  73. public function setZbiory($zbiory){$this->zbiory = $zbiory;}
  74.  
  75. public function getWynik() {return $this->wynik;}
  76. public function suma()
  77. {
  78.  
  79. $wynik = $this->zbiory[0];
  80. $ilosc = count($this->zbiory);
  81.  
  82. for($i=1; $i<$ilosc; $i++)
  83. {
  84. $tablica = $this->zbiory[$i];
  85.  
  86. $wynik=array_merge($wynik,$tablica);
  87. $wynik= array_unique($wynik);
  88.  
  89. }
  90. $this->wynik =$wynik;
  91. }
  92.  
  93. public function roznica(){}
  94. public function iloczyn(){}
  95.  
  96. }
  97.  
  98. PROGRAM JAO
  99.  
  100. <?php
  101.  
  102. include_once "./OperacjeNaZbiorach.php";
  103.  
  104. include_once "./OdczytDanych.php";
  105.  
  106. /*
  107. * To change this license header, choose License Headers in Project Properties.
  108. * To change this template file, choose Tools | Templates
  109. * and open the template in the editor.
  110. */
  111.  
  112. /**
  113. * Description of ProgramJAO
  114. *
  115. * @author student
  116. */
  117.  
  118. class ProgramJAO {
  119.  
  120. public $wynik;
  121.  
  122. public function main() {
  123. $zbiory = array(); // 1
  124. $zbior = array(); // 2
  125. $odczytDanych = new OdczytDanych(); //punkt 1
  126. $odczytDanych->setNazwaPliku("dane.txt"); //punkt 2
  127. $odczytDanych->odczytaj(); //punkt 3
  128. $zbiory = $odczytDanych->getZbiory(); //punkt 4
  129. print_r($zbiory);
  130. $operacjeNaZbiorach = new OperacjeNaZbiorach(); //punkt 5
  131. $operacjeNaZbiorach->setZbiory($zbiory); //punkt 6
  132. $operacjeNaZbiorach->suma(); //punkt 7
  133. $operacjeNaZbiorach ->getWynik(); //punkt 8
  134. $this->wynik=$operacjeNaZbiorach->getWynik();
  135. }
  136. }
  137.  
  138. INDEX.PHP
  139.  
  140. <?php
  141.  
  142. require_once "./ProgramJAO.php";
  143.  
  144. /*
  145. * To change this license header, choose License Headers in Project Properties.
  146. * To change this template file, choose Tools | Templates
  147. * and open the template in the editor.
  148. */
  149. $program = new ProgramJAO();
  150. $program->main();
  151. print_r($program->wynik);
  152. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement