complex.h

来自「Rayleigh channel model」· C头文件 代码 · 共 48 行

H
48
字号
#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 + =
减小字号Ctrl + -
显示快捷键?