新手 ,求指导
#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 图片挂了 file:///C:/Users/Administrator/Desktop/QQ%E6%88%AA%E5%9B%BE20150313125309.jpg我运行没问题
页:
[1]