Infiniti_Inter

задание 6 (Olya)

Jan 21st, 2020
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.50 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <fstream>
  4. #include <string>
  5. #include <queue>
  6. using namespace std;
  7. ifstream in("input.txt");
  8. ofstream out("output.txt");
  9.  
  10. class Vector
  11. {
  12. public:
  13.     Vector() {};
  14.     Vector(int x, int y) { this->x = x; this->y = y; }
  15.     void Print()
  16.     {
  17.         out << "(" << x << ", " << y << ")\n";
  18.     }
  19.     void PrintW()
  20.     {
  21.         out << "(" << x << ", " << y << ")";
  22.     }
  23.     double Range()
  24.     {
  25.         return sqrt(sqr(x) + sqr(y));
  26.     }
  27.     static bool Compare(Vector a, Vector b)
  28.     {
  29.         return a.Range() == b.Range();
  30.     }
  31.     Vector operator + (Vector a)
  32.     {
  33.         Vector b = Vector(this->x + a.x, this->y + a.y);
  34.         return b;
  35.     }
  36.     Vector operator - (Vector a)
  37.     {
  38.         Vector b = Vector(this->x - a.x, this->y - a.y);
  39.         return b;
  40.     }
  41.  
  42.     int operator *(Vector a)
  43.     {
  44.         return x * a.x + y * a.y;
  45.     }
  46.     template<typename T> Vector operator*(T scalar)//умножение на скаляр
  47.     {
  48.         Vector b = Vector(this->x * scalar, this->y * scalar);
  49.         return b;
  50.     }
  51.     Vector operator()(Vector a, Vector b) {//векторное произведение
  52.  
  53.         Vector с = Vector(a.y - b.y, b.x - a.x);
  54.         return с;
  55.  
  56.     }
  57. private:
  58.     int x, y;
  59.  
  60.    
  61.     long long sqr(int a) { return a * a; }
  62.    
  63.  
  64.    
  65.    
  66.  
  67. };
  68.  
  69. int main()
  70. {
  71.     Vector a(1, 1);
  72.     Vector b(1, 0);
  73.     out << "[ab] = ";
  74.     (a, b).Print();
  75.     out << "a - b = ";
  76.     Vector c = a - b;
  77.     c.Print();
  78.     int k = 5;
  79.     out << "a * k = ";
  80.     a = a * k;
  81.     a.Print();
  82.     a.PrintW();
  83.     if (Vector::Compare(a, b))
  84.         out << " = ";
  85.     else
  86.         out << " <> ";
  87.     b.PrintW();
  88.    
  89.  
  90. }
Add Comment
Please, Sign In to add comment