Guest User

Untitled

a guest
Aug 19th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.52 KB | None | 0 0
  1. class Rozdzial
  2. {
  3. public:
  4.     char* nazwa;
  5.     char* text;
  6.  
  7. };
  8.  
  9.  
  10. class Ksiazka
  11. {
  12.     int iloscStron;
  13.     Rozdzial** rozdzialy;
  14.     int iloscRozdzialow;
  15.  
  16. public:
  17.  
  18.     Ksiazka()
  19.     {
  20.         this->rozdzialy = new Rozdzial*[1];
  21.         this->iloscRozdzialow = 1;
  22.     }
  23.     Ksiazka(int i)
  24.     {
  25.         this->iloscStron = i;
  26.         this->rozdzialy = new Rozdzial*[1];
  27.         this->iloscRozdzialow = 1;
  28.     }
  29.  
  30.  
  31.  
  32.     ~Ksiazka()
  33.     {
  34.         delete [] this->rozdzialy;
  35.     }
  36.  
  37.     void dodajRozdzial(Rozdzial r)
  38.     {
  39.         Rozdzial** noweRozdzialy = new Rozdzial*[this->iloscRozdzialow];
  40.         for(int i = 0; i<this->iloscRozdzialow; i+=1)
  41.         {
  42.             try
  43.             {
  44.                 *noweRozdzialy[i] = *this->rozdzialy[i];
  45.             }
  46.             catch(bad_alloc)
  47.             {
  48.                 *noweRozdzialy[i] =  r;
  49.             }
  50.         }
  51.         this->iloscRozdzialow+=1;
  52.         delete [] this->rozdzialy;
  53.         this->rozdzialy = noweRozdzialy;
  54.     }
  55.     void dodajRozdzial(Rozdzial* r)
  56.     {
  57.         Rozdzial newr = *r;
  58.         this->dodajRozdzial(newr);
  59.     }
  60.     void dodajRozdzialref(Rozdzial& r)
  61.     {
  62.         Rozdzial newr = r;
  63.         this->dodajRozdzial(newr);
  64.     }
  65.     void showRozdzialy()
  66.     {
  67.         for(int i = 0; i<this->iloscRozdzialow; i+=1)
  68.         {
  69.             cout << (*this->rozdzialy[i]).nazwa;
  70.         }
  71.     }
  72.     void showRozdzial(int k)
  73.     {
  74.         cout << (*this->rozdzialy[k]).nazwa;
  75.     }
  76.  
  77.     Ksiazka* operator++()
  78.     {
  79.         this->iloscRozdzialow+=1;
  80.         return this;
  81.     }
  82.     Ksiazka* operator++(int)
  83.     {
  84.         Ksiazka* k = this;
  85.         this->iloscRozdzialow+=1;
  86.         return this;
  87.     }
  88.     Ksiazka operator+(Ksiazka k)
  89.     {
  90.         Ksiazka newk();
  91.         k.iloscStron = this->iloscStron+k.iloscStron;
  92.         k.iloscRozdzialow = this->iloscRozdzialow+k.iloscRozdzialow;
  93.  
  94.         Rozdzial** noweRozdzialy = new Rozdzial*[k.iloscRozdzialow];
  95.         for(int i = 0; i<k.iloscRozdzialow; i+=1)
  96.         {
  97.             try
  98.             {
  99.                 *noweRozdzialy[i] = *this->rozdzialy[i];
  100.             }
  101.             catch(bad_alloc)
  102.             {
  103.                 *noweRozdzialy[i] = *k.rozdzialy[i];
  104.             }
  105.         }
  106.         return k;
  107.     }
  108.  
  109.  
  110.     friend ostream& operator<<(ostream& str, const Ksiazka& k) ;
  111. };
  112.  
  113. ostream& operator<<(ostream& str, const Ksiazka& k)
  114. {
  115.  
  116.     for(int i = 0; i<k.iloscRozdzialow; i+=1)
  117.     {
  118.         str << (*k.rozdzialy[i]).nazwa;
  119.     }
  120.     return str;
  121. }
Add Comment
Please, Sign In to add comment