Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <conio.h>
- #include <string.h>
- #include <cstring>
- #include <math.h>
- #include <cstdlib>
- #include <ctime>
- using namespace std;
- /* struct arr // объявление типа данных - структура
- {
- int i;
- char cp [80];
- };
- arr Murzik ={1,
- "Good kitten!"};
- int main ()
- {
- cout <<Murzik.cp<<" ";
- int j, n;
- cin >> n;
- arr *p= new arr [n];
- for(j=0; j<n; j++)
- {
- cin>>p[j].cp;
- p[j].i=strlen(p[j].cp);
- }
- for (j=n-1; j>=0; j--)
- {
- cout<<p[j].cp<<" ";
- cout<<p[j].i<<"\n";
- }
- return 0;
- } */
- class Vector
- {
- private:
- double x, y;
- public:
- Vector(double a, double b)
- {
- // message();
- set_x(a);
- set_y(b);
- }
- Vector(double a)
- {
- y = 0;
- // message();
- set_x(a);
- }
- Vector()
- {
- x = 1;
- y = 0;
- // message();
- }
- void message ()
- {
- // cout << "Создан объект" << endl;
- }
- void set_x(double a)
- {
- x = a;
- }
- void set_y(double b)
- {
- y = b;
- }
- void show()
- {
- cout << "x=" << x << "\n" << "y=" << y << endl;
- }
- /* void stretch()
- {
- double n;
- cout << "Введите число n, в которое хотите \"растянуть\" вектор: " << endl;
- cin >> n;
- cout << "x=" << n*x << "\n" << "y=" << n*y;
- }
- void mod()
- {
- cout << "Модуль \"нерастянутого\" вектора: " << sqrt(x*x + y*y);
- }
- Vector sum(Vector V)
- {
- Vector vec;
- vec.x = x + V.x;
- vec.y = y + V.y;
- return vec;
- } */
- Vector operator-()
- {
- return Vector(-x, -y);
- }
- // friend Vector operator-(const Vector&, const Vector&);
- Vector operator*(int a)
- {
- return Vector(x*a, y*a);
- }
- // friend Vector operator*(const int, const Vector&);
- Vector& operator+=(const Vector &V2)
- {
- x += V2.x;
- y += V2.y;
- return *this;
- }
- Vector& operator-=(const Vector &V2)
- {
- x -= V2.x;
- y -= V2.y;
- return *this;
- }
- Vector operator++(int c)
- {
- return Vector(x+c, y+c);
- }
- ~Vector()
- {
- // cout << "Удален объект" << endl;
- }
- };
- int main ()
- {
- double a, b;
- int c = 1;
- setlocale (LC_ALL, "Rus");
- cout << "Введите координату вектора x: " << endl;
- cin >> a;
- cout << "Введите координату вектора y: " << endl;
- cin >> b;
- Vector V1(a, b);
- Vector V2(a);
- Vector V3;
- cout << "Координаты вектора V1: " << endl ;
- V1.show();
- cout << "Координаты вектора V2: " << endl ;
- V2.show();
- cout << "Координаты вектора V3: " << endl ;
- V3.show();
- // V3.sum(V1).show();
- cout << "Координаты вектора -V1: " << endl ;
- (-V1).show();
- cout << "Координаты вектора 2*V1: " << endl ;
- (V1*2).show();
- cout << "Координаты суммы векторов V1 и V2: " << endl ;
- V1 += V2;
- V1.show();
- cout << "Координаты разности векторов V3 и V2: " << endl ;
- V3 -= V2;
- V3.show();
- (V1++).show();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement