编写复数类CComplex,实现整数与实数,复数与复数之间的加.减.乘等各种基本运算

来源:百度知道 编辑:UC知道 时间:2024/09/27 15:55:48

#include <iostream.h>
#include <cstdlib>
#include <cmath>
class CComplex
{
public:
friend double real (const CComplex&);
friend double imag (const CComplex&);
friend CComplex operator + (const CComplex&, const CComplex&);
friend CComplex operator - (const CComplex&, const CComplex&);
friend CComplex operator * (const CComplex&, const CComplex&);
friend CComplex operator / (const CComplex&, const CComplex&);
friend bool operator == (const CComplex&, const CComplex&);
friend bool operator != (const CComplex&, const CComplex&);
friend CComplex polar (double, double);
friend istream& operator>> (istream&, CComplex&);
friend ostream& operator<< (ostream&, const CComplex&);
CComplex (double r = 0, double i = 0): re (r), im (i) { }
double real () const { return re; }
double imag () const { return im; }
private:
double re, im;
};
double norm (const