📄 complex.h
字号:
#ifndef COMPLEX
#define COMPLEX
#include <iostream.h>
class Complex {
double re, im;
public:
Complex():re(0),im(0){}
Complex(double r):re(r),im(0){}
Complex(double x, double y):re(x),im(y){}
/* So we can initialize a Complex as:
Complex b=3;
Complex c(22,16);
Complex d;
Also these declarations are useful for conversions:
ie, although we define only Complex operator+(Complex c2)
we can do: b=22+c; and it will automatically convert 22 to a Complex
*/
void show_Complex() {
cout << re << " ";
cout << im << "\n";
}
Complex operator+(Complex c2);
Complex operator+=(Complex c2);
Complex operator-(Complex c2);
Complex operator-=(Complex c2);
Complex operator*(Complex c2);
Complex operator*=(Complex c2);
Complex operator/(Complex c2);
Complex operator/=(Complex c2);
Complex operator=(Complex c2);
/* Useful functions */
double real() {return re;}
double imag() {return im;}
friend double abs(Complex c2);
friend ostream& operator<<(ostream& s,Complex a)
{ return s<<" "<<a.real()<<" "<<a.imag()<<" "; }
};
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -