Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <complex>
- class Vector {
- std::complex<double> components[4] = {}; // массив из 4 элементов ct, x, y, z
- public:
- Vector() {}
- Vector(std::complex<double> ct, std::complex<double> x, std::complex<double> y, std::complex<double> z) {
- components[0] = ct;
- components[1] = x;
- components[2] = y;
- components[3] = z;
- }
- Vector operator+(const Vector &other) { // к текущему ветору прибавляется еще один
- Vector result; // создание нового вектора - результата.
- for (int i = 0; i < 4; i++) {
- result.components[i] = components[i] +
- other.components[i]; // поэлементное сложение текущего векторая и того что справа от него
- }
- return result;
- }
- Vector operator-(const Vector &other) { // то же самое только с минусом
- Vector result; // создание нового вектора - результата.
- for (int i = 0; i < 4; i++) {
- result.components[i] = components[i] -
- other.components[i]; // поэлементное сложение текущего векторая и того что справа от него
- }
- return result;
- }
- std::complex<double> interval(const Vector &other) { // это используется так: double x = v1.interval(v2);
- Vector diff = *this - other; // вычитаем из текущего вектора тот который подали в аргументе
- return pow(diff.components[0], 2) -
- pow(diff.components[1], 2) -
- pow(diff.components[2], 2) -
- pow(diff.components[3], 2);
- }
- };
- int main() {
- Vector v1(1,2,3,4);
- Vector v2(2,2,2,2);
- std::cout << v1.interval(v2) << std::endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement