|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#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 |
|