Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- #include <fstream>
- #include <string>
- #include <queue>
- using namespace std;
- ifstream in("input.txt");
- ofstream out("output.txt");
- class Vector
- {
- public:
- Vector() {};
- Vector(int x, int y) { this->x = x; this->y = y; }
- void Print()
- {
- out << "(" << x << ", " << y << ")\n";
- }
- void PrintW()
- {
- out << "(" << x << ", " << y << ")";
- }
- double Range()
- {
- return sqrt(sqr(x) + sqr(y));
- }
- static bool Compare(Vector a, Vector b)
- {
- return a.Range() == b.Range();
- }
- Vector operator + (Vector a)
- {
- Vector b = Vector(this->x + a.x, this->y + a.y);
- return b;
- }
- Vector operator - (Vector a)
- {
- Vector b = Vector(this->x - a.x, this->y - a.y);
- return b;
- }
- int operator *(Vector a)
- {
- return x * a.x + y * a.y;
- }
- template<typename T> Vector operator*(T scalar)//умножение на скаляр
- {
- Vector b = Vector(this->x * scalar, this->y * scalar);
- return b;
- }
- Vector operator()(Vector a, Vector b) {//векторное произведение
- Vector с = Vector(a.y - b.y, b.x - a.x);
- return с;
- }
- private:
- int x, y;
- long long sqr(int a) { return a * a; }
- };
- int main()
- {
- Vector a(1, 1);
- Vector b(1, 0);
- out << "[ab] = ";
- (a, b).Print();
- out << "a - b = ";
- Vector c = a - b;
- c.Print();
- int k = 5;
- out << "a * k = ";
- a = a * k;
- a.Print();
- a.PrintW();
- if (Vector::Compare(a, b))
- out << " = ";
- else
- out << " <> ";
- b.PrintW();
- }
Add Comment
Please, Sign In to add comment