wuyaosheng1990 发表于 2015-3-13 11:53:54

新手 ,求指导

#include <iostream>

using namespace std;

class Complex
{
public:

    Complex();
    Complex(double r,double i);
    Complex complex_add(Complex &d);
    void prin();

private:
    double real;
    double imag;
};

Complex::Complex()
{
    real = 0;
    imag = 0;
}

Complex::Complex(double r, double i)
{
    real = r;
    imag = i;
}

Complex Complex::complex_add(Complex &d)
{

    Complex c;

    c.real = real + d.real;
    c.imag = imag + d.imag;

    return c;
}

void Complex::prin()
{
    cout << "(" << real << ", " << imag << "i)\n";
}


int main()
{
    Complex c1(3,4);
    Complex c2(5,-10);
    Complex c3;

    c3 = c1.complex_add(c2);

    cout << "c1 = ";
    c1.prin();
    cout << "c2 = ";
    c2.prin();
    cout << "c1 + c2 = ";
    c3.prin();

    return 0;

}

提示错误
C:\Users\lenovo\Desktop

wuyaosheng1990 发表于 2015-3-13 11:54:50

图片挂了

不要叫我小六 发表于 2015-3-13 12:54:41

file:///C:/Users/Administrator/Desktop/QQ%E6%88%AA%E5%9B%BE20150313125309.jpg我运行没问题
页: [1]
查看完整版本: 新手 ,求指导