Иван Мухин
Мыслитель
(6290)
3 года назад
#include <iostream>
#include <vector>
#include <cmath>
#include <tuple>
using namespace std;
struct X1 { // coordinate x1
int value;
explicit X1(int v) : value(v) {}
};
struct Y1 { // coordinate y1
int value;
explicit Y1(int v) : value(v) {}
};
struct X2 { // coordinate x2
int value;
explicit X2(int v) : value(v) {}
};
struct Y2 { // coordinate y2
int value;
explicit Y2(int v) : value(v) {}
};
class MathVector {
const int x1_, y1_, x2_, y2_;
const double length_;
public:
MathVector() : x1_(0), y1_(0), x2_(0), y2_(0), length_(0) {}
MathVector(X1 x1, Y1 y1, X2 x2, Y2 y2)
:x1_(x1.value), y1_(y1.value), x2_(x2.value), y2_(y2.value),
length_(sqrt(pow(x2_ - x1_, 2) + pow(y2_ - y1_, 2))) {}
auto GetCordinates() const {
return tie(x1_, y1_, x2_, y2_);
}
double GetLength() const {return length_;}
friend bool IsParallel (const MathVector& left, const MathVector& right) {
return left.GetCordinates() == right.GetCordinates();
}
};
int main() {
MathVector v1{X1(1), Y1(1), X2(5), Y2(4)};
MathVector v2{X1(1), Y1(1), X2(5), Y2(4)};
cout << (IsParallel(v1, v2) ? "equal\n" : "not equal\n");
MathVector v3{X1(1), Y1(1), X2(5), Y2(4)};
MathVector v4{X1(1), Y1(1), X2(5), Y2(5)};
cout << (IsParallel(v3, v4) ? "equal\n" : "not equal\n");
}