Guest User

Untitled

a guest
May 16th, 2018
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.88 KB | None | 0 0
  1. //Mateusz Przybyla
  2. #include <iostream>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <map>
  6. using namespace std;
  7.  
  8. class Zadanie
  9. {
  10. public:
  11.     const int id;
  12.     static int ileUtworzono;
  13.     static int ileObiektow;
  14.     static map < const int, Zadanie* > lista;
  15.     void ( * akcja ) ( const Zadanie & );
  16.  
  17.     Zadanie ( void funkcja ( const Zadanie &z ) = 0 ) : id ( ++ileUtworzono )
  18.     {
  19.         ileObiektow++;
  20.         akcja = funkcja;
  21.             lista [ id ] = this;
  22.     }
  23.  
  24.     Zadanie ( const Zadanie & z ) : id ( ++ileUtworzono )
  25.     {
  26.         ileObiektow++;
  27.         akcja = z.akcja;
  28.         lista [ id ] = this;
  29.     }
  30.  
  31.     ~Zadanie ()
  32.     {
  33.         ileObiektow--;
  34.         map < const int, Zadanie * > :: iterator i;
  35.         for ( i = lista.begin(); i != lista.end(); i++ )
  36.         {
  37.             if ( ( *i ).second == this )
  38.             {
  39.                 lista.erase ( i );
  40.                 break;
  41.             }
  42.         }
  43.     }
  44.  
  45.     void wykonaj ()
  46.     {
  47.         if ( akcja == 0 )
  48.             cout << "BRAK AKCJI" << endl;
  49.         else
  50.             akcja ( *this );
  51.     }
  52.  
  53.     static void wykonaj ( const int numer )
  54.     {
  55.         bool czyJest = false;
  56.         map < const int, Zadanie * > :: iterator i;
  57.         for ( i = lista.begin(); i != lista.end(); i++ )
  58.             if ( ( *i ).first == numer )
  59.             {
  60.                 ( *i ).second->wykonaj();
  61.                 czyJest = true;
  62.             }
  63.         if ( !czyJest )
  64.             cout << "BRAK ZADANIA" << endl;
  65.     }
  66.  
  67.     void zmien ( void funkcja ( const Zadanie & z ) = 0 )
  68.     {
  69.         akcja = funkcja;
  70.     }
  71.  
  72.     static void raport ()
  73.     {
  74.         cout << "[ " << ileUtworzono << " | " << ileObiektow << " | ";
  75.         map < const int, Zadanie * > :: iterator i;
  76.         for ( i = lista.begin(); i != lista.end(); i++ )
  77.             cout << ( *i ).first << " ";
  78.         cout << "]" << endl;
  79.     }
  80. };
  81.  
  82. int Zadanie :: ileObiektow = 0;
  83. int Zadanie :: ileUtworzono = 0;
  84. map < const int, Zadanie* > Zadanie :: lista;
Add Comment
Please, Sign In to add comment