Advertisement
Guest User

CppLOL

a guest
Oct 18th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.36 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     int ilosc_ludzi;
  9.  
  10.     cout << "Podaj dlugosc kolejki: ";
  11.     cin >> ilosc_ludzi;
  12.     cout << "\n";
  13.  
  14.     Czlowiek** ludzie = new (nothrow) Czlowiek*[ilosc_ludzi];
  15.  
  16.     for (int i = 0; i < ilosc_ludzi; i++)
  17.     {
  18.         if (i % 2)
  19.         {
  20.             ludzie[i] = new (nothrow) Pracownik(i);
  21.         }
  22.         else
  23.         {
  24.             ludzie[i] = new (nothrow) Student(i);
  25.         }
  26.     }
  27.  
  28.     for (int n = 0; n < ilosc_ludzi; n++)
  29.     {
  30.         (*ludzie[n]).przedstawSie();
  31.         (*ludzie[n]).pij();
  32.     }
  33.  
  34. };
  35.  
  36.  
  37. class Czlowiek
  38. {
  39. protected:
  40.     string imie;
  41.     string nazwisko;
  42. public:
  43.     virtual void pij() = 0;
  44.  
  45.     virtual void przedstawSie()
  46.     {
  47.         cout << "Jestem " << imie << " " << nazwisko <<"\n";
  48.     }
  49. };
  50.  
  51. class Student :public Czlowiek
  52. {
  53. private:
  54.     int nr_indeksu;
  55. public:
  56.     void pij()
  57.     {
  58.         for (int i = 0; i < 3; i++) {
  59.             cout << imie << " " << "PIJE JAK STUDENT" << "\n";
  60.         }
  61.     }
  62.  
  63.     void przedstawSie()
  64.     {
  65.         cout << "Jestem " << imie << " " << nazwisko << " " << nr_indeksu << "\n";
  66.     }
  67.  
  68.     Student(int par)
  69.     {
  70.         this->imie = "Student " + par;
  71.         this->nazwisko = "Studencki " + par;
  72.         this->nr_indeksu = 136690 + par;
  73.     }
  74. };
  75.  
  76. class Pracownik :public Czlowiek
  77. {
  78. public:
  79.     void pij()
  80.     {
  81.         cout << "PIJE JAK PRACOWNIK" << "\n";
  82.     }
  83.  
  84.     Pracownik(int par)
  85.     {
  86.         this->imie = "Pracownik " + par;
  87.         this->nazwisko = "Pracownicki  " + par;
  88.     }
  89. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement