金庸武学排行:C++定义类问题?

来源:百度文库 编辑:高考问答 时间:2024/05/05 12:29:59
C++定义类问题?

写出下列类的定义,不必写出方法代码

1. 定义满足下列要求的复数类CComplex:
(1) 重载适用于复数的四则运算符、关系运算符;
(2) 用一个成员函数求复数的实部和虚部;
(3) 求复数的模;
(4) 求共轭复数。

class CComplex
{
public:
CComplex();
CComplex(int x, int y=0);
CComplex(const CComplex &);

CComplex operator+(const CComplex &);
CComplex operator-(const CComplex &);
CComplex operator*(const CComplex &);
CComplex operator/(const CComplex &);
bool operator<(const CComplex &);
bool operator<=(const CComplex &);
bool operator>(const CComplex &);
bool operator>=(const CComplex &);
bool operator==(const CComplex &);
bool operator!=(const CComplex &);

void twopart(int &realpart, int &imaginarypart);
unsigned module();

CComplex conjugate();
private:
int real;
int imaginary;
};