Advertisement
kanciastopantalones

kolos bez komentarzy

Jan 16th, 2014
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.54 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. class platnosc {
  4. private:
  5. char * nazwa;
  6. double kwota;
  7. int dzien;
  8. int miesiac;
  9. int rok;
  10. public:
  11. platnosc(char * nazwa, double kwota, int dzien, int miesiac, int rok) : nazwa(nazwa), kwota(kwota), dzien(dzien), miesiac(miesiac), rok(rok){}
  12. ~platnosc(){
  13. delete[] nazwa;
  14. }
  15.  
  16. bool operator< (const platnosc & plat) const{
  17. if (rok < plat.rok) return true;
  18. if (rok > plat.rok) return false;
  19. if (miesiac < plat.miesiac) return true;
  20. if (miesiac > plat.miesiac) return false;
  21. if (dzien < plat.dzien) return true;
  22. if (dzien > plat.dzien) return false;
  23.  
  24. return false;
  25. }
  26. };
  27.  
  28. class stos_platnosci {
  29. protected:
  30. platnosc ** tab;
  31. int rozmiar;
  32. int pozycja;
  33.  
  34. public:
  35.  
  36. stos_platnosci(int rozmiar){
  37. this->rozmiar = rozmiar;
  38. this->pozycja = -1;
  39. this->tab = new platnosc*[rozmiar];
  40. }
  41.  
  42. platnosc * operator-=(int temp){
  43. if (this->pozycja == -1) return nullptr;
  44. platnosc * plat = this->tab[this->pozycja];
  45. delete this->tab[this->pozycja];
  46. this->pozycja--;
  47. return plat;
  48. }
  49.  
  50. virtual bool put(platnosc * plat){
  51. if ((this->rozmiar - this->pozycja) == 1) return false;
  52. this->pozycja++;
  53. this->tab[this->pozycja] = plat;
  54. return true;
  55. }
  56.  
  57.  
  58. int pobierzPozycje(){
  59. return this->pozycja;
  60. }
  61.  
  62. platnosc ** pobierzTablice(){
  63. return this->tab;
  64. }
  65.  
  66. int pobierzRozmiar(){
  67. return this->rozmiar;
  68. }
  69. };
  70.  
  71. class kolejka_wydatkow : public stos_platnosci {
  72. private:
  73.  
  74. void czysc(){
  75. if (this->pozycja > -1)
  76. for (int i = 0; i <= this->pozycja; i++)
  77. delete this->tab[i];
  78. this->pozycja = -1;
  79. delete[] this->tab;
  80. }
  81. public:
  82.  
  83. ~kolejka_wydatkow(){
  84. this->czysc();
  85. }
  86.  
  87.  
  88. bool put(platnosc * plat){
  89. if ((this->rozmiar - this->pozycja) == 1) return false;
  90. this->pozycja++;
  91.  
  92. if (this->pozycja == 0){
  93. this->tab[this->pozycja] = plat;
  94. return true;
  95. }
  96. for (int i = this->pozycja - 1; i > 0; i--){
  97. if (this->tab[i] < plat){
  98.  
  99. this->tab[i + 1] = this->tab[i];
  100. }else{
  101.  
  102. this->tab[i + 1] = plat;
  103. return true;
  104. }
  105. }
  106.  
  107. this->tab[0] = plat;
  108. return true;
  109. }
  110.  
  111. bool operator=(stos_platnosci &stos){
  112. if (stos.pobierzPozycje() == -1) return false;
  113.  
  114. this->czysc();
  115.  
  116. this->tab = new platnosc*[stos.pobierzRozmiar()];
  117. this->rozmiar = stos.pobierzRozmiar();
  118. platnosc ** tablica = stos.pobierzTablice();
  119.  
  120. for (int i = 0; i <= stos.pobierzPozycje(); i++)
  121. this->put(tablica[i]);
  122. return true;
  123. }
  124. };
  125.  
  126.  
  127.  
  128. int _tmain(int argc, _TCHAR* argv[])
  129. {
  130. return 0;
  131. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement