Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #define ELFY 5
- using namespace std;
- class elfiaZygota
- {
- protected:
- int prod;
- public:
- virtual ~elfiaZygota(){};
- virtual int zwrocProd()=0;
- };
- class elf : public elfiaZygota
- {
- public:
- elf();
- virtual int zwrocProd();
- };
- elf::elf()
- {
- cout<<"Tu elf."<<endl;
- prod=5;
- }
- int elf::zwrocProd()
- {
- return prod;
- }
- class superElf : public elf
- {
- protected:
- int sila;
- public:
- superElf(int a, int b);
- virtual int zwrocProd();
- };
- superElf::superElf(int a, int b)
- {
- cout<<"Tu superElf."<<endl;
- prod=a;
- sila=b;
- }
- int superElf::zwrocProd()
- {
- return sila*prod;
- }
- class elfMutant : public elfiaZygota
- {
- public:
- elfMutant();
- virtual int zwrocProd();
- };
- elfMutant::elfMutant()
- {
- cout<<"Tu elfMutant."<<endl;
- prod=-2;
- }
- int elfMutant::zwrocProd()
- {
- return prod;
- }
- class goblin : public elfMutant
- {
- protected:
- int sila;
- public:
- goblin(int a, int b);
- virtual int zwrocProd();
- goblin operator+(elf& arg);
- };
- goblin::goblin(int a, int b)
- {
- cout<<"Tu goblin."<<endl;
- int c;
- c=a*-1;
- prod=c;
- sila=b;
- }
- int goblin::zwrocProd()
- {
- return prod*sila;
- }
- goblin goblin::operator+(elf& arg)
- {
- goblin tmp(elf.zwrocProd(), 2);
- return tmp;
- }
- void obliczProdukcje(elfiaZygota* tablicaElfow[ELFY])
- {
- int suma=0;
- cout<<endl;
- for (int i=0; i<ELFY; i++)
- {
- suma= suma+tablicaElfow[i]->zwrocProd();
- }
- if(suma>0)
- cout<<"tak";
- else cout<< "nie";
- }
- int main () {
- elfiaZygota* tablicaElfow[ELFY];
- elf Lesnik;
- tablicaElfow[0] = (elfiaZygota*)&Lesnik;
- tablicaElfow[1] = new elfMutant();
- tablicaElfow[2] = new elf();
- tablicaElfow[3] = new superElf(6, 3);
- tablicaElfow[4] = new goblin(5, 3);
- obliczProdukcje(tablicaElfow);
- cout << "Oj, jeden z elfΓ³w zmutowaΕ..." << endl;
- goblin Gobus(1,1);
- Gobus = Gobus+Lesnik;
- tablicaElfow[0] = (elfiaZygota*)&Gobus;
- obliczProdukcje(tablicaElfow);
- for (int i=1; i<ELFY; i++)
- {
- delete tablicaElfow[i];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement