Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #define ELFY 5
- using namespace std;
- class elf {
- protected:
- int prod, zycie;
- public:
- elf()
- {
- cout<<"Tu elf 1"<<endl;
- prod = 5;
- zycie = 5;
- liczbaElfow++;
- }
- elf(int a, int b)
- {
- cout<<"Tu elf 2"<<endl;
- prod = a;
- zycie = b;
- liczbaElfow++;
- }
- virtual ~elf(){};
- virtual int zrobZabawke(int dzien)
- {
- if(dzien<zycie)
- {
- return prod;
- } else {return 0;}
- }
- static int liczbaElfow;
- };
- class superElf : public elf {
- protected:
- int sila;
- public:
- superElf(int a, int b, int c)
- {
- cout<<"Tu superElf"<<endl;
- prod = a;
- sila = b;
- zycie = c;
- liczbaSuperElfow++;
- }
- virtual int zrobZabawke(int dzien)
- {
- if(dzien<zycie)
- {
- return sila*prod;
- } else {return 0;}
- }
- static int liczbaSuperElfow;
- };
- int elf::liczbaElfow=0;
- int superElf::liczbaSuperElfow=0;
- string czyElfySieWyrobia(elf* tablicaElfow[ELFY], int d, const int z) {
- int praca=0;
- for(int i=0; i<ELFY;i++)
- {
- praca += tablicaElfow[i]->zrobZabawke(d);
- }
- if(praca>=z)
- {
- return "tak";
- }else {return "nie";}
- }
- int main () {
- elf* tablicaElfow[ELFY];
- tablicaElfow[0] = new elf();
- tablicaElfow[1] = new elf(2,10);
- tablicaElfow[2] = new elf(3,6);
- tablicaElfow[3] = new superElf(4, 2, 5);
- tablicaElfow[4] = new superElf(2, 15, 1);
- cout << "Elfow jest: " << elf::liczbaElfow << endl;
- cout << "W tym super elfow jest: " << superElf::liczbaSuperElfow << endl;
- const int dni = 7;
- int tablicaZadan[dni] = {18, 33, 13, 12, 5, 2, 20};
- for (int i=0; i<dni; i++) {
- cout << "Dzien " << i << ". Czy elfy dadza rade: " << czyElfySieWyrobia(tablicaElfow, i,tablicaZadan[i]) << endl;
- }
- for (int i=0; i<ELFY; i++) {
- delete tablicaElfow[i];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement