Advertisement
Komandor_Astrii

kol1

Jun 22nd, 2017
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.91 KB | None | 0 0
  1. #include <iostream>
  2. #include <conio.h>
  3.  
  4. using namespace std;
  5.  
  6. class Czlowiek
  7. {
  8. private:
  9.     int szczescie;
  10. public:
  11.     Czlowiek(){}
  12.     Czlowiek(int szczescie)
  13.     {
  14.         this->szczescie=szczescie;
  15.     }
  16.     int getSzczescie()
  17.     {
  18.         return szczescie;
  19.     }
  20.  
  21.     Czlowiek operator/(Czlowiek &cz);
  22. };
  23.  
  24. Czlowiek Czlowiek::operator/(Czlowiek &cz)
  25. {
  26.     Czlowiek kopia((this->szczescie)*(cz.getSzczescie()));
  27.     return kopia;
  28. }
  29.  
  30. ostream &operator<<(ostream& str, Czlowiek& cz)
  31. {
  32.     str<<"Pomnozone szczescie: "<<cz.getSzczescie();
  33.     return str;
  34. }
  35.  
  36. int main()
  37. {
  38.     int szczescie1,szczescie2;
  39.     cout<<"Podaj szczescie pierwszej osoby: ";
  40.     cin>>szczescie1;
  41.  
  42.     cout<<"Podaj szczescie drugiej osoby: ";
  43.     cin>>szczescie2;
  44.  
  45.     Czlowiek cz1(szczescie1);
  46.     Czlowiek cz2(szczescie2);
  47.  
  48.     Czlowiek cz3 = cz1/cz2;
  49.     cout<<cz3<<endl;
  50.  
  51.     getch();
  52.     return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement