Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- using namespace std;
- class Vector
- {
- private: int x, y;
- public: Vector() : x(0), y(0)
- {
- }
- Vector(int x, int y) :x(x), y(y)
- {
- }
- void ShowData()
- {
- cout << "(" << x << "," << y << ")";
- cout << endl;
- }
- double GetDlina()
- {
- return sqrt(x*x + y*y);
- }
- bool operator== (const Vector &v1)
- {
- return (x == v1.x && y == v1.y);
- }
- Vector add(Vector d)
- {
- Vector result;
- result.x = x + d.x;
- result.y = y + d.y;
- return result;
- }
- Vector sub(Vector d)
- {
- Vector result;
- result.x = x - d.x;
- result.y = y - d.y;
- return result;
- }
- double scal(Vector right)
- {
- return x*right.x + y*right.y;
- }
- };
- int main()
- {
- int x, y, x2, y2;
- cout << "Enter x && y=";
- cin >> x >> y;
- Vector v(x, y);
- cout << "Enter x2 && y2=";
- cin >> x2 >> y2;
- Vector v1(x2, y2);
- v.ShowData();
- v1.ShowData();
- cout << v.GetDlina() << endl;
- cout << v1.GetDlina() << endl;
- cout << v.scal(v1) << endl;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment