Advertisement
Guest User

Untitled

a guest
Apr 20th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. class Vector {
  2. public:
  3. double x_, y_;
  4. Vector(double x = 0, double y = 0)
  5. {
  6. this->x_ = x;
  7. this->y_ = y;
  8. }
  9. void print(int precision = 2, bool newLine = true)
  10. {
  11. cout << "(" << setprecision (precision) << fixed << this->x_ << ", " << setprecision (precision) << fixed << this->y_ << ")";
  12. if (newLine) cout << endl;
  13. }
  14. Vector add (const Vector& v) const
  15. {
  16. Vector ret;
  17. ret.x_ = this->x_ + v.x_;
  18. ret.y_ = this->y_ + v.y_;
  19. return ret;
  20. }
  21. Vector& addTo (const Vector& v)
  22. {
  23. this->x_ += v.x_;
  24. this->y_ += v.y_;
  25. return *this;
  26. }
  27. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement