fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Vector {
  5. private:
  6. int x, y;
  7.  
  8. public:
  9. Vector() : x(0), y(0) {}
  10.  
  11. Vector(int x, int y) : x(x), y(y) {}
  12.  
  13. void Input() {
  14. cin >> x >> y;
  15. }
  16.  
  17. void Out() const {
  18. cout << x << " " << y << endl;
  19. }
  20.  
  21. Vector& operator=(const Vector& other) {
  22. if (this != &other) {
  23. x = other.x;
  24. y = other.y;
  25. }
  26. return *this;
  27. }
  28.  
  29. Vector operator+(const Vector& other) const {
  30. return Vector(x + other.x, y + other.y);
  31. }
  32.  
  33. Vector operator-(const Vector& other) const {
  34. return Vector(x - other.x, y - other.y);
  35. }
  36.  
  37. Vector& operator+=(const Vector& other) {
  38. x += other.x;
  39. y += other.y;
  40. return *this;
  41. }
  42.  
  43. Vector& operator-=(const Vector& other) {
  44. x -= other.x;
  45. y -= other.y;
  46. return *this;
  47. }
  48.  
  49. int operator*(const Vector& other) const {
  50. return x * other.x + y * other.y;
  51. }
  52. };
  53.  
  54.  
  55. int main() {
  56. Vector a, b(3, 4), c;
  57.  
  58. a.Input();
  59.  
  60. a.Out();
  61.  
  62. b.Out();
  63.  
  64. c = a + b;
  65. c.Out();
  66.  
  67. c -= b;
  68. c.Out();
  69.  
  70. int scalar = a * b;
  71. cout << scalar << endl;
  72.  
  73. return 0;
  74. }
Success #stdin #stdout 0.01s 5308KB
stdin
Standard input is empty
stdout
0 0
3 4
3 4
0 0
0