1 条题解

  • 0
    @ 2020-02-04 15:48:20

    #include <iostream>
    using namespace std;
    class Complex
    {
    int real, imaginary;
    public:
    Complex() {}
    Complex(int a, int b) { real = a; imaginary = b; }
    Complex plus(Complex a, Complex b)
    {
    Complex c;
    c.real = a.real + b.real;
    c.imaginary = a.imaginary + b.imaginary;
    return c;
    }
    Complex multiply(Complex a, Complex b)
    {
    Complex c;
    c.real = a.real * b.real - a.imaginary * b.imaginary;
    c.imaginary = a.imaginary * b.real + a.real * b.imaginary;
    return c;
    }
    void Output()
    {
    if (imaginary > 0)cout << real << '+' << imaginary << 'i' << endl;
    else if (imaginary == 0)cout << real << endl;
    else
    cout << real << imaginary << 'i' << endl;
    }
    };
    int main()
    {
    int x[3][2];
    for (int i = 0; i < 3; i++)cin >> x[i][0] >> x[i][1];
    Complex a(x[0][0], x[0][1]), b(x[1][0], x[1][1]), c(x[2][0], x[2][1]), d, e;
    d = d.plus(a, b); e = e.plus(d, c); e.Output();
    d = d.multiply(a, b); e = e.multiply(d, c); e.Output();
    }

  • 1

OO2-1 复数类的算术、赋值运算符的重载

信息

ID
1011
难度
6
分类
(无)
标签
递交数
684
已通过
181
通过率
26%
被复制
5
上传者