Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // fewrfwer.cpp: определяет точку входа для консольного приложения.
- //
- #include "stdafx.h"
- #include <iostream>
- #include <conio.h>
- #include <math.h>
- using namespace std;
- class Vector
- {
- private:
- double x, y;
- public:
- Vector()
- {
- x = 0;
- y = 0;
- }
- Vector(double a, double b)
- {
- x = a;
- y = b;
- }
- double PrX()
- {
- return x;
- }
- double PrY()
- {
- return y;
- }
- double Lenght()
- {
- return sqrt(x*x + y*y);
- }
- friend ostream& operator<<(ostream& o, const Vector& v);
- friend Vector operator+(Vector v1, Vector v2);
- friend Vector operator-(Vector v1, Vector v2);
- friend Vector operator*(double k, Vector v2);
- };
- // v1.dot(v2) -> v1.x*v2.x + v1.y*v2.y = |v1|*|v2|*cos(angle|
- // x1*y2 - y1*x2 = |v1|*|v2|*sin(angle)
- // atan2(cos, sin) = {-pi, pi)
- // v1.angle(v2) ->
- Vector operator+(Vector v1, Vector v2)
- {
- return Vector(v1.x + v2.x, v1.y + v2.y);
- }
- Vector operator-(Vector v1, Vector v2)
- {
- Vector res;
- res.x = v1.x - v2.x;
- res.y = v1.y - v2.y;
- return res;
- }
- Vector operator*(double k, Vector v2)
- {
- Vector res;
- res.x = k*v2.x;
- res.y = k*v2.y;
- return res;
- }
- ostream& operator<<(ostream& o, const Vector& v)
- {
- o << '(' << v.x << ", " << v.y << ')';
- return o;
- }
- //class SuperVector : public Vector
- //{
- //public:
- // SuperVector() : Vector()
- // {}
- //
- // SuperVector(0, 0) : Complex(0, 0)
- //
- //};
- int _tmain(int argc, _TCHAR* argv[])
- {
- Vector v1 = Vector();
- Vector v2 = Vector(3,4);
- Vector v3 = Vector(-2,1);
- double k = -12;
- cout << "v1 = " << v1 << ", v2 = " << v2 << ", v3 = " << v3 << '\n';
- cout << "v1 + v2 = " << v1 + v2 << ", v2 + v3 = " << v2 + v3 << ", v1 + v2 + v3 = " << v1 + v2 + v3 << '\n';
- cout << "v1 - v2 = " << v1 - v2 << ", v2 - v3 = " << v2 - v3 << ", v1 - v2 - v3 = " << v1 - v2 - v3 << '\n';
- cout << "k*v2 = " << k*v2 << '\n';
- cout << "Proectia na osi X vectora v2: " << v2.PrX() << ", Proectia na osi Y vectora v3: " << v3.PrY() << '\n';
- cout << "Dlina vectora v2: " << v2.Lenght();
- getch();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement