Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <ctime>
- #include <cstdlib>
- using namespace std;
- class zwierze
- {
- public:
- zwierze() { cout << "Konstruktor zwierze" << endl; }
- virtual~zwierze() { cout << "Destruktor zwierze" << endl; }
- virtual void opis() { cout << "Metoda zwierze" << endl; }
- };
- class ssak: public zwierze
- {
- public:
- ssak () { cout << "Konstruktor ssak" << endl; }
- virtual ~ssak() { cout << "Destruktor ssak" << endl; }
- virtual void opis() { cout << "Metoda ssak" << endl; }
- };
- class czlowiek: public ssak
- {
- public:
- czlowiek() { cout << "Konstruktor czlowiek" << endl; }
- ~czlowiek() { cout << "Destruktor czlowiek" << endl; }
- void opis() { cout << "Metoda czlowiek" << endl; }
- };
- class ptak: public zwierze
- {
- public:
- ptak() { cout << "Konstruktor ptak" << endl; }
- ~ptak() { cout << "Destruktor ptak" << endl; }
- void opis() { cout << "Metoda ptak" << endl; }
- };
- zwierze* funkcja()
- {
- srand(time(NULL));
- int wartosc=rand() % 5;
- switch (wartosc)
- {
- case (0): {return new zwierze;break;}
- case (1): {return new ssak;break;}
- case (2): {return new czlowiek;break;}
- case (3): {return new ptak;break;}
- case (4): {NULL;}
- }
- };
- int main()
- {
- char znak;
- do
- {
- zwierze* wsk=funkcja();
- if (wsk!=NULL)
- wsk->opis();
- else
- cout<<"Pusty los"<<endl;
- delete wsk;
- cin>>znak;
- } while (znak!='q');
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement