SHARE
TWEET

Untitled

Lera_rastaturina Oct 21st, 2019 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "pch.h"
  2. #include "Vector2d.h"
  3. #include <iostream>
  4. #include <cmath>
  5. #include <cstring>
  6.  
  7. using namespace std;
  8.  
  9. Vector2d::Vector2d()
  10. {
  11.     x = 0;
  12.     y = 0;
  13. }
  14.  
  15. Vector2d::Vector2d(double x, double y)
  16. {
  17.     this->x = x;
  18.     this->y = y;
  19. }
  20.  
  21. Vector2d::Vector2d(double x_1, double x_2, double y_1, double y_2)
  22. {
  23.     this->x = x_1;
  24.     this->y = y_1;
  25.     this->x = x_2;
  26.     this->y = y_2;
  27. }
  28.  
  29. Vector2d::Vector2d(const Vector2d & v)
  30. {
  31.     x = v.x;
  32.     y = v.y;
  33. }
  34.  
  35. Vector2d Vector2d::operator+(const Vector2d & v) const
  36. {
  37.     return Vector2d(x + v.x, y + v.y);
  38. }
  39.  
  40. Vector2d Vector2d::operator-(const Vector2d & v) const
  41. {
  42.     return Vector2d(x-v.x, y-v.y);
  43. }
  44.  
  45. Vector2d Vector2d::operator*(const Vector2d & v) const
  46. {
  47.     return Vector2d(x*v.x, y*v.y);
  48. }
  49.  
  50. Vector2d& Vector2d::operator++()
  51. {
  52.     x++;
  53.     y++;
  54.     return *this;
  55. }
  56.  
  57. Vector2d Vector2d::operator++(int)
  58. {
  59.     Vector2d temp(x, y);
  60.     x++;
  61.     y++;
  62.     return temp;
  63. }
  64.  
  65. Vector2d & Vector2d::operator--()
  66. {
  67.     x--;
  68.     y--;
  69.     return *this;
  70. }
  71.  
  72. Vector2d Vector2d::operator--(int)
  73. {
  74.     Vector2d temp(x, y);
  75.     x--;
  76.     y--;
  77.     return temp;
  78. }
  79.  
  80. const Vector2d & Vector2d::operator+=(const Vector2d &v)
  81. {
  82.     x += v.x;
  83.     y += v.y;
  84.     return *this;
  85. }
  86.  
  87. const Vector2d & Vector2d::operator-=(const Vector2d &v)
  88. {
  89.     x -= v.x;
  90.     y -= v.y;
  91.     return *this;
  92. }
  93.  
  94. const Vector2d & Vector2d::operator*=(const Vector2d &v)
  95. {
  96.     x *= v.x;
  97.     y *= v.y;
  98.     return *this;
  99. }
  100.  
  101. Vector2d::operator string() const
  102. {
  103.     string s = "(" + to_string(x) + ";" + to_string(y) + ")" ;
  104.     return s;
  105. }
  106.  
  107. Vector2d operator*(double r, Vector2d & v)
  108. {
  109.     return r*v;
  110. }
  111.  
  112.  
  113.  
  114. Vector2d::~Vector2d()
  115. {
  116.  
  117. }
  118.  
  119. void Vector2d::print(void)
  120. {
  121.     std::cout << x << std::endl;
  122.     std::cout << y << std::endl;
  123. }
  124.  
  125. void Vector2d::sum(Vector2d b)
  126. {
  127.     x = x + b.x;
  128.     y = y + b.y;
  129. }
  130.  
  131. void Vector2d::sub(Vector2d b)
  132. {
  133.     x = x - b.x;
  134.     y = y - b.y;
  135. }
  136.  
  137. void Vector2d::mult(double b)
  138. {
  139.     x = x*b;
  140.     y = y*b;
  141. }
  142.  
  143.  
  144.  
  145. double Vector2d::scalarMult(Vector2d V)
  146. {
  147.     x = V.x*x;
  148.     y = V.y*y;
  149.     return (x,y);
  150. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top