Не бейте, я не знаю, что я написал. Надеюсь, тебе это .
#include <iostream>
#include <vector>
using namespace std;
template<typename a, typename b>
class myPair {
public:
myPair(a first, b second) : first(first), second(second) {
}
myPair operator+(myPair a) {
return myPair(first + a.first, second + a.second);
}
myPair operator-(myPair a) {
return operator+(myPair(-a.first, -a.second));
}
a first;
b second;
};
class complex : myPair<int, int> {
public:
friend myPair;
complex(int real, int imaginary) : myPair(real, imaginary) {
}
int real() {
return first;
}
int imaginary() {
return second;
}
complex operator+(complex a) {
return complex(myPair::operator+(a).first, myPair::operator+(a).second);
}
complex operator-(complex a) {
return complex(myPair::operator-(a).first, myPair::operator-(a).second);
}
complex operator*(complex a) {
return complex(real() * a.real(), imaginary() * a.imaginary());
}
};
int main() {
complex a(1, 2), b(10, 11);
cout << (a + b).real() << " " << (a + b).imaginary() << " " << (a - b).real() << " " << (a - b).imaginary() << " " << (a * b).real() << " " << (a * b).imaginary();
}
Пояснение: НЕ - инверсия (логическое отрицание) => нечетное меняем на четное. Проверяем второй и третий вариант ответа: (4598>100) - да (4598 четное) - да (5432>100) - да (5432 четное) - да