Advertisement
Guest User

Untitled

a guest
Mar 30th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.20 KB | None | 0 0
  1. // fewrfwer.cpp: определяет точку входа для консольного приложения.
  2. //
  3.  
  4.  
  5.  
  6. #include "stdafx.h"
  7. #include <iostream>
  8. #include <conio.h>
  9. #include <math.h>
  10.  
  11.  
  12. using namespace std;
  13.  
  14. class Vector
  15. {
  16. private:
  17.     double x, y;
  18. public:
  19.     Vector()
  20.     {
  21.         x = 0;
  22.         y = 0;
  23.     }
  24.     Vector(double a, double b)
  25.     {
  26.         x = a;
  27.         y = b;
  28.     }
  29.     double PrX()
  30.     {
  31.         return x;
  32.     }
  33.     double PrY()
  34.     {
  35.         return y;
  36.     }
  37.     double Lenght()
  38.     {
  39.         return sqrt(x*x + y*y);
  40.     }
  41.     friend ostream& operator<<(ostream& o, const Vector& v);
  42.     friend Vector operator+(Vector v1, Vector v2);
  43.     friend Vector operator-(Vector v1, Vector v2);
  44.     friend Vector operator*(double k, Vector v2);
  45. };
  46.  
  47. // v1.dot(v2)   -> v1.x*v2.x + v1.y*v2.y = |v1|*|v2|*cos(angle|
  48.  
  49. // x1*y2 - y1*x2 = |v1|*|v2|*sin(angle)
  50. // atan2(cos, sin) = {-pi, pi)
  51. // v1.angle(v2) ->
  52.  
  53. Vector operator+(Vector v1, Vector v2)
  54. {
  55.     return Vector(v1.x + v2.x, v1.y + v2.y);
  56. }
  57.  
  58. Vector operator-(Vector v1, Vector v2)
  59. {
  60.     Vector res;
  61.     res.x = v1.x - v2.x;
  62.     res.y = v1.y - v2.y;
  63.     return res;
  64. }
  65.  
  66. Vector operator*(double k, Vector v2)
  67. {
  68.     Vector res;
  69.     res.x = k*v2.x;
  70.     res.y = k*v2.y;
  71.     return res;
  72. }
  73.  
  74. ostream& operator<<(ostream& o, const Vector& v)
  75. {
  76.     o << '(' << v.x << ", " << v.y << ')';
  77.     return o;
  78. }
  79.  
  80. //class SuperVector : public Vector
  81. //{
  82. //public:
  83. //  SuperVector() : Vector()
  84. //  {}
  85. //
  86. //  SuperVector(0, 0) : Complex(0, 0)
  87. // 
  88. //};
  89. int _tmain(int argc, _TCHAR* argv[])
  90. {
  91.     Vector v1 = Vector();
  92.     Vector v2 = Vector(3,4);
  93.     Vector v3 = Vector(-2,1);
  94.     double k = -12;
  95.     cout << "v1 = " << v1 << ", v2 = " << v2 << ", v3 = " << v3 << '\n';
  96.     cout << "v1 + v2 = " << v1 + v2 << ", v2 + v3 = " << v2 + v3 << ", v1 + v2 + v3 = " << v1 + v2 + v3 << '\n';
  97.     cout << "v1 - v2 = " << v1 - v2 << ", v2 - v3 = " << v2 - v3 << ", v1 - v2 - v3 = " << v1 - v2 - v3 << '\n';
  98.     cout << "k*v2 = " << k*v2 << '\n';
  99.     cout << "Proectia na osi X vectora v2: " << v2.PrX() << ", Proectia na osi Y vectora v3: " << v3.PrY() << '\n';
  100.     cout << "Dlina vectora v2: " << v2.Lenght();
  101.     getch();
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement