Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <conio.h>
- #include <string.h>
- class Browar
- {
- public:
- Browar(const unsigned int);
- private:
- unsigned int procentPiwa;
- };
- class Klub
- {
- public:
- Klub& operator ++ (void); //LiczbaPiw
- Klub& operator -- (void); //LiczbaPiw
- Klub& operator += (const unsigned int);
- void Wyswietl(void) const;
- protected:
- Klub(const char * const, const unsigned int, const unsigned int);
- ~Klub(void);
- unsigned int liczbaOsob;
- unsigned int liczbaPiw;
- char* nazwaKlubu;
- };
- Klub::Klub(const char * const nazwaKlubu, const unsigned int liczbaOsob, const unsigned int liczbaPiw)
- {
- size_t size = strlen(nazwaKlubu);
- this->nazwaKlubu = new char[size];
- strcpy(this->nazwaKlubu, nazwaKlubu);
- this->liczbaOsob = liczbaOsob;
- this->liczbaPiw = liczbaPiw;
- }
- Klub::~Klub(void)
- {
- delete[] nazwaKlubu;
- }
- Klub& Klub::operator ++ (void)
- {
- ++liczbaPiw;
- return *this;
- }
- Klub& Klub::operator -- (void)
- {
- --liczbaPiw;
- return *this;
- }
- Klub& Klub::operator += (const unsigned int count)
- {
- liczbaOsob += count;
- return *this;
- }
- void Klub::Wyswietl(void) const
- {
- printf("Klub: %s, Osob: %i, Piw: %i \n", nazwaKlubu, liczbaOsob, liczbaPiw);
- }
- class Spirala : public Klub
- {
- public:
- Spirala(const char * const, const unsigned int, const unsigned int);
- ~Spirala();
- Spirala& operator += (const unsigned int);
- private:
- Browar* Piwka[30];
- };
- Spirala::Spirala(const char * const nazwaKlubu, const unsigned int liczbaOsob, const unsigned int liczbaPiw)
- : Klub(nazwaKlubu, liczbaOsob, liczbaPiw)
- {
- for(unsigned int i = 0; i < 30; i ++)
- Piwka[i] = new Browar(5);
- }
- Spirala::~Spirala()
- {
- for(unsigned int i = 0; i < 30; i ++)
- if(Piwka[i] != NULL) delete Piwka[i];
- }
- Spirala& Spirala::operator += (const unsigned int count)
- {
- liczbaPiw += count;
- return *this;
- }
- class Zoom : private Klub
- {
- public:
- Zoom(const char * const, const unsigned int, const unsigned int);
- Zoom& operator ++ (void); //LiczbaPiw
- Zoom& operator -- (void); //LiczbaPiw
- Zoom& operator += (const unsigned int);
- void Wyswietl(void) const;
- };
- void Zoom::Wyswietl(void) const
- {
- printf("Klub: %s, Osob: %i, Piw: %i \n", nazwaKlubu, liczbaOsob, liczbaPiw);
- }
- Zoom::Zoom(const char * const nazwaKlubu, const unsigned int liczbaOsob, const unsigned int liczbaPiw)
- : Klub(nazwaKlubu, liczbaOsob, liczbaPiw)
- { }
- Zoom& Zoom::operator ++ (void)
- {
- ++liczbaPiw;
- return *this;
- }
- Zoom& Zoom::operator -- (void)
- {
- --liczbaPiw;
- return *this;
- }
- Zoom& Zoom::operator += (const unsigned int count)
- {
- liczbaOsob += count;
- return *this;
- }
- Browar::Browar(const unsigned int)
- {
- procentPiwa = 5;
- }
- int main()
- {
- Zoom Klub1("Zoom", 100, 10);
- Spirala Klub2("Spirala", 100, 10);
- Klub1--;
- Klub2++;
- Klub2 += 5;
- Klub1 += 5;
- Klub1.Wyswietl();
- Klub2.Wyswietl();
- _getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement