Dvortsov_D1

общая сумма векторов через классы

Mar 13th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.45 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4. class vector{
  5. public:
  6.     float x;
  7.     float y;
  8. public:
  9.     vector (float x_,float y_) : x(x_), y(y_) { }
  10.     void print(){
  11.         cout << x << '\t' << y << endl;
  12.     }
  13.     vector add(vector b){
  14.         return vector(x + b.x, y + b.y);
  15.     }
  16.    
  17. };
  18.  
  19.  
  20. int main()
  21. {
  22.     vector a(1, 2);
  23.     a.print();
  24.     vector bbbb(1, 2);
  25.     bbbb.print();
  26.     vector c = a.add(bbbb);
  27.     c.print();
  28. }
Advertisement
Add Comment
Please, Sign In to add comment