Advertisement
smsites

Untitled

Apr 28th, 2015
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.89 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <conio.h>
  3. #include <string.h>
  4.  
  5. class Browar
  6. {  
  7.     public:
  8.         Browar(const unsigned int);
  9.  
  10.     private:
  11.         unsigned int procentPiwa;
  12. };
  13.  
  14.  
  15. class Klub
  16. {
  17.     public:
  18.         Klub& operator ++ (void); //LiczbaPiw
  19.         Klub& operator -- (void); //LiczbaPiw
  20.         Klub& operator += (const unsigned int);
  21.  
  22.         void Wyswietl(void) const;
  23.  
  24.     protected:
  25.         Klub(const char * const, const unsigned int, const unsigned int);
  26.         ~Klub(void);
  27.  
  28.         unsigned int liczbaOsob;
  29.         unsigned int liczbaPiw;
  30.         char* nazwaKlubu;
  31. };
  32.  
  33. Klub::Klub(const char * const nazwaKlubu, const unsigned int liczbaOsob, const unsigned int liczbaPiw)
  34. {
  35.     size_t size = strlen(nazwaKlubu);
  36.     this->nazwaKlubu = new char[size];
  37.     strcpy(this->nazwaKlubu, nazwaKlubu);
  38.  
  39.     this->liczbaOsob = liczbaOsob;
  40.     this->liczbaPiw = liczbaPiw;
  41. }
  42.  
  43. Klub::~Klub(void)
  44. {
  45.     delete[] nazwaKlubu;
  46. }
  47.  
  48. Klub& Klub::operator ++ (void)
  49. {
  50.     ++liczbaPiw;
  51.     return *this;
  52. }
  53.  
  54. Klub& Klub::operator -- (void)
  55. {
  56.     --liczbaPiw;
  57.     return *this;
  58. }
  59.  
  60. Klub& Klub::operator += (const unsigned int count)
  61. {
  62.     liczbaOsob += count;
  63.     return *this;
  64. }
  65.  
  66. void Klub::Wyswietl(void) const
  67. {
  68.     printf("Klub: %s, Osob: %i, Piw: %i \n", nazwaKlubu, liczbaOsob, liczbaPiw);
  69. }
  70.  
  71. class Spirala : public Klub
  72. {
  73.     public:
  74.         Spirala(const char * const, const unsigned int, const unsigned int);
  75.         ~Spirala();
  76.  
  77.         Spirala& operator += (const unsigned int);
  78.  
  79.     private:
  80.         Browar* Piwka[30];
  81. };
  82.  
  83. Spirala::Spirala(const char * const nazwaKlubu, const unsigned int liczbaOsob, const unsigned int liczbaPiw)
  84.     : Klub(nazwaKlubu, liczbaOsob, liczbaPiw)
  85. {
  86.     for(unsigned int i = 0; i < 30; i ++)
  87.         Piwka[i] = new Browar(5);
  88. }
  89.  
  90. Spirala::~Spirala()
  91. {
  92.     for(unsigned int i = 0; i < 30; i ++)
  93.         if(Piwka[i] != NULL) delete Piwka[i];
  94. }
  95.  
  96. Spirala& Spirala::operator += (const unsigned int count)
  97. {
  98.     liczbaPiw += count;
  99.     return *this;
  100. }
  101.  
  102. class Zoom : private Klub
  103. {
  104.     public:
  105.         Zoom(const char * const, const unsigned int, const unsigned int);
  106.  
  107.         Zoom& operator ++ (void); //LiczbaPiw
  108.         Zoom& operator -- (void); //LiczbaPiw
  109.         Zoom& operator += (const unsigned int);
  110.  
  111.         void Wyswietl(void) const;
  112. };
  113.  
  114. void Zoom::Wyswietl(void) const
  115. {
  116.     printf("Klub: %s, Osob: %i, Piw: %i \n", nazwaKlubu, liczbaOsob, liczbaPiw);
  117. }
  118.  
  119. Zoom::Zoom(const char * const nazwaKlubu, const unsigned int liczbaOsob, const unsigned int liczbaPiw)
  120.     : Klub(nazwaKlubu, liczbaOsob, liczbaPiw)
  121. { }
  122.  
  123. Zoom& Zoom::operator ++ (void)
  124. {
  125.     ++liczbaPiw;
  126.     return *this;
  127. }
  128.  
  129. Zoom& Zoom::operator -- (void)
  130. {
  131.     --liczbaPiw;
  132.     return *this;
  133. }
  134.  
  135. Zoom& Zoom::operator += (const unsigned int count)
  136. {
  137.     liczbaOsob += count;
  138.     return *this;
  139. }
  140.  
  141. Browar::Browar(const unsigned int)
  142. {
  143.     procentPiwa = 5;
  144. }
  145.  
  146. int main()
  147. {
  148.     Zoom Klub1("Zoom", 100, 10);
  149.     Spirala Klub2("Spirala", 100, 10);
  150.  
  151.     Klub1--;
  152.     Klub2++;
  153.     Klub2 += 5;
  154.     Klub1 += 5;
  155.  
  156.     Klub1.Wyswietl();
  157.     Klub2.Wyswietl();
  158.  
  159.     _getch();
  160.     return 0;
  161. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement