Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class Pair
- {
- public:
- Pair(int a, int b)
- {
- _a = a;
- _b = b;
- }
- Pair Sum(Pair &p)
- {
- Pair *p2 = new Pair(p._a + _a, p._b + _b);
- return *p2;
- }
- int MultAB()
- {
- return _a * _b;
- }
- void out()
- {
- cout << "(" << _a << "," << _b << ")" << endl;
- }
- protected:
- int _a,_b;
- private:
- };
- class Complex : public Pair
- {
- public:
- Complex(int a, int b) : Pair(a,b) {};
- Complex Mult(Complex &c)
- {
- Complex *c2 = new Complex(c._a * _a - c._b * _b, c._a * _b + c._b * _a);
- return *c2;
- }
- Complex Diff(Complex &c)
- {
- Complex *c2 = new Complex(_a - c._a, _b - c._b);
- return *c2;
- }
- protected:
- private:
- };
- int main()
- {
- cout << "Введите первое число" << endl;
- int a,b;
- cout << "Введите действительную часть: ";
- cin >> a;
- cout << "Введите мнимую часть: ";
- cin >> b;
- Complex c1 = *(new Complex(a,b));
- cout << "Введите второе число" << endl;
- cout << "Введите действительную часть: ";
- cin >> a;
- cout << "Введите мнимую часть: ";
- cin >> b;
- Complex c2 = *(new Complex(a,b));
- Pair res = c1.Sum(c2);
- cout << "Сумма: ";
- res.out();
- cout << endl;
- res = c1.Diff(c2);
- cout << "Разность: ";
- res.out();
- cout << endl;
- res = c1.Mult(c2);
- cout << "Произведение: ";
- res.out();
- cout << endl;
- cout << "Произведение полей первого числа: ";
- cout << c1.MultAB() << endl;
- cout << "Произведение полей второго числа: ";
- cout << c2.MultAB() << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement