[C++] Complex numbers structure in C++

Source consists of header file complex.h that include constructors and functions, and implementation of constructors and functions in complex.cpp

List of constructors and functions

Constructors
  • Kompleksni() - creates complex number equal to 0.
  • Kompleksni(double x) - creates complex number equal to real number x.
  • Kompleksni(double re,double im) - creates complex number re+im*i.
Functions
  • void konjugiraj() - turns the complex number function was called on to complex conjugate number
  • void dodaj(Kompleksni z) - adds to complex number function was called on the complex number z
  • void pomnozi(Kompleksni z) - multiplies to complex number function was called on the complex number z
  • int potenciraj(double x) - powers the complex number function was called on and returns 0. If the complex number is 0 and x is or 0 or negative, return 0.
  • double modul() - returns the apsolute value (modulus) of complex number function was called on
  • double arg()- returns the argument (angle) of complex number function was called on
  • int isApprox(Kompleksni z,int k) - if the distance between complex number function was called on and complex number Z is lesser than 10^-k, return 1, else return 0.
  • double re() - returns the real part of complex number function was called on
  • double im() - returns the imaginary part of complex number function was called on

Sources

Header file - complex.h
Implementation file - complex.cpp

Structure successfully compiles under:

  • [x86]gcc version 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)
  • [x86]Mingw/GCC 3.4.2
  • [x86]gcc version 3.3 [Win XP]
  • [IA64]gcc version 4.1.2 ia64-hp-hpux11.23
  • [m68k]gcc version 2.95.3 20010125 (prerelease, propolice)
  • [powerpc]gcc version 2.95.3 19991030 (prerelease)