Advertisement
Guest User

Untitled

a guest
May 27th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.94 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class Wektor {
  6. private:
  7.     float x;
  8.     float y;
  9.  
  10. public:
  11.     Wektor(float xx, float yy) {
  12.         x = xx;
  13.         y = yy;
  14.     }
  15.  
  16.     Wektor() {
  17.         x = 0;
  18.         y = 0;
  19.     }
  20.  
  21.     Wektor operator + (const Wektor& w) {
  22.         Wektor nowy;
  23.         nowy.x = x + w.x;
  24.         nowy.y = y + w.y;
  25.  
  26.         return nowy;
  27.     }
  28.  
  29.     bool operator != (const Wektor& w) {
  30.         return (x != w.x || y != w.y);
  31.     }
  32.  
  33.     bool operator == (const Wektor& w) {
  34.         return (x == w.x && y == w.y);
  35.     }
  36.  
  37.     void wypisz() {
  38.         cout<<"x = "<<x<<" y = "<<y<<endl;
  39.     }
  40. };
  41.  
  42. int main()
  43. {
  44.     Wektor w(4.0, 2.0);
  45.     Wektor v(1.0, 1.5);
  46.     Wektor y(4.0, 2.0);
  47.  
  48.     Wektor z = w + v;
  49.  
  50.     w.wypisz();
  51.     v.wypisz();
  52.     cout<<"---------------\n";
  53.     z.wypisz();
  54.  
  55.     cout<<std::boolalpha<<(w != y)<<endl;
  56.     cout<<std::boolalpha<<(w == y)<<endl;
  57.  
  58.     return 0;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement