|
#include "iostream.h"
class CComplex
{
private:
double real;
double imag;
public:
CComplex();
CComplex(double r, double i);
CComplex(CComplex &c); //复数类的拷贝构造函数声明
void Set(double r, double i);
void Print();
CComplex Add(CComplex c);
CComplex Sub(CComplex c);
};
CComplex::CComplex()
{
real = 0.0;
imag = 0.0;
}
CComplex::CComplex (double r, double i)
{
real = r;
imag = i;
}
CComplex::CComplex (CComplex &c) //复数类的拷贝构造函数定义
{
real = c.real;
imag = c.imag;
}
void CComplex::Set(double r, double i)
{
real = r;
imag = i;
}
void CComplex::Print()
{
cout << "(" << real << "," << imag << ")" << endl;
}
CComplex CComplex::Add(CComplex c)
{
CComplex temp;
temp.real = real + c.real;
temp.imag = imag + c.imag; |
|