Advertisement
Khristina

Задача №3 (не закончена)

Mar 27th, 2018
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.49 KB | None | 0 0
  1. #include <iostream>
  2. #include <conio.h>
  3. #include <string.h>
  4. #include <cstring>
  5. #include <math.h>
  6. #include <cstdlib>
  7. #include <ctime>
  8.     using namespace std;
  9.    /* struct arr // объявление типа данных - структура
  10.     {
  11.         int i;
  12.         char cp [80];
  13.     };
  14. arr Murzik ={1,
  15.              "Good kitten!"};
  16.     int main ()
  17.     {
  18.         cout <<Murzik.cp<<" ";
  19.         int j, n;
  20.         cin >> n;
  21.         arr *p= new arr [n];
  22.         for(j=0; j<n; j++)
  23.         {
  24.             cin>>p[j].cp;
  25.             p[j].i=strlen(p[j].cp);
  26.         }
  27. for (j=n-1; j>=0; j--)
  28. {
  29.     cout<<p[j].cp<<" ";
  30.     cout<<p[j].i<<"\n";
  31. }
  32. return 0;
  33.     } */
  34.  class Vector
  35.  {
  36.     private:
  37.      double x, y;
  38.     public:
  39.      Vector(double a, double b)
  40.      {
  41.   //       message();
  42.          set_x(a);
  43.          set_y(b);
  44.      }
  45.      Vector(double a)
  46.      {
  47.          y = 0;
  48.  //        message();
  49.          set_x(a);
  50.      }
  51.      Vector()
  52.      {
  53.          x = 1;
  54.          y = 0;
  55.   //       message();
  56.      }
  57.      void message ()
  58.      {
  59.    //      cout << "Создан объект" << endl;
  60.      }
  61.      void set_x(double a)
  62.      {
  63.          x = a;
  64.      }
  65.      void set_y(double b)
  66.      {
  67.          y = b;
  68.      }
  69.      void show()
  70.      {
  71.          cout << "x=" << x << "\n" << "y=" << y << endl;
  72.      }
  73.   /*   void stretch()
  74.      {
  75.          double n;
  76.          cout << "Введите число n, в которое хотите \"растянуть\" вектор: " << endl;
  77.          cin >> n;
  78.          cout << "x=" << n*x << "\n" << "y=" << n*y;
  79.      }
  80.      void mod()
  81.      {
  82.          cout << "Модуль \"нерастянутого\" вектора: " << sqrt(x*x + y*y);
  83.      }
  84.      Vector sum(Vector V)
  85.      {
  86.          Vector vec;
  87.          vec.x = x + V.x;
  88.          vec.y = y + V.y;
  89.          return vec;
  90.      } */
  91.      Vector operator-()
  92.     {
  93.         return Vector(-x, -y);
  94.     }
  95.  
  96. //  friend Vector operator-(const Vector&, const Vector&);
  97.  
  98.     Vector operator*(int a)
  99.     {
  100.         return Vector(x*a, y*a);
  101.     }
  102.  
  103. //  friend Vector operator*(const int, const Vector&);
  104.  
  105.     Vector& operator+=(const Vector &V2)
  106.     {
  107.         x += V2.x;
  108.         y += V2.y;
  109.         return *this;
  110.     }
  111.  
  112.     Vector& operator-=(const Vector &V2)
  113.     {
  114.         x -= V2.x;
  115.         y -= V2.y;
  116.         return *this;
  117.     }
  118.  
  119.     Vector operator++(int c)
  120.     {
  121.         return Vector(x+c, y+c);
  122.     }
  123.  
  124.      ~Vector()
  125.      {
  126.    //    cout << "Удален объект" << endl;
  127.      }
  128.  };
  129.  
  130.  int main ()
  131.  {
  132.      double a, b;
  133.      int c = 1;
  134.      setlocale (LC_ALL, "Rus");
  135.      cout << "Введите координату вектора x: " << endl;
  136.      cin >> a;
  137.      cout << "Введите координату вектора y: " << endl;
  138.      cin >> b;
  139.      Vector V1(a, b);
  140.      Vector V2(a);
  141.      Vector V3;
  142.      cout << "Координаты вектора V1: " << endl ;
  143.      V1.show();
  144.      cout << "Координаты вектора V2: " << endl ;
  145.      V2.show();
  146.      cout << "Координаты вектора V3: " << endl ;
  147.      V3.show();
  148.   //   V3.sum(V1).show();
  149.      cout << "Координаты вектора -V1: " << endl ;
  150.      (-V1).show();
  151.      cout << "Координаты вектора 2*V1: " << endl ;
  152.      (V1*2).show();
  153.      cout << "Координаты суммы векторов V1 и V2: " << endl ;
  154.      V1 += V2;
  155.      V1.show();
  156.      cout << "Координаты разности векторов V3 и V2: " << endl ;
  157.      V3 -= V2;
  158.      V3.show();
  159.      (V1++).show();
  160.     return 0;
  161.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement