Advertisement
Paszta

Obiektówka laby 4 chyba, klasa ze zwierzetami

Oct 30th, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.21 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class zwierze{
  6.  
  7.     string imie;
  8.     static int liczba;
  9.  
  10.  public:
  11.     zwierze( string im){
  12.         imie = im;
  13.         liczba++;
  14.     }
  15.     void ustawImie(){
  16.         cout << " Podaj imie zwierzecia: " << endl;
  17.         cin >> imie;
  18.  
  19.     }
  20.     const string& naLancuch(){  // zwraca stala ref
  21.         return imie;
  22.     }
  23.  
  24.     static int ileZwierzat(){
  25.         return liczba;
  26.     }
  27.  
  28. };
  29.  
  30. int zwierze::liczba=0;
  31. bool porownanie(zwierze z1, zwierze z2){
  32.     if(z1.naLancuch() == z2.naLancuch()) return true;
  33.     else return false;
  34.  
  35. }
  36.  
  37. int main()
  38. {
  39.     zwierze z1("Tadek");
  40.     zwierze z2("Henri");
  41.     cout << " Jak nazywa sie pierwsze zwierze? " << z1.naLancuch() << endl;
  42.     cout << " Jak nazywa sie drugie zwierze? " << z2.naLancuch() << endl;
  43.     cout << porownanie(z1, z2) << endl;
  44.     cout << " Zmiana imienia pierwszego zwierzecia " << endl;
  45.     z1.ustawImie();
  46.     cout << " Jak nazywa sie pierwsze zwierze? " << z1.naLancuch() << endl;
  47.     cout << " Jak nazywa sie drugie zwierze? " << z2.naLancuch() << endl;
  48.     cout << porownanie(z1, z2) << endl;
  49.  
  50.     cout << " Liczba zwierzat wynosi: " << zwierze::ileZwierzat() << endl;
  51.     return 0;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement