Complex

Abstract Complex Concrete Complex Representation Invariant for Complex Numbers

COMPLEX NUMBER IMPLEMENTATION

#include <iostream.h>

class complex {
  int real, imag;
  public:
  complex ();
  void read ();
  void write ();
  int iszero ();
  void add (complex C1, complex C2);
};

complex::complex () {
  real = imag = 0;
}

void complex::read () {
  cin >> real >> imag;
}

void complex::write () {
  cout << real <<" + "<< imag << 'i';
}

int complex::iszero () {
  return (real ==0 && imag == 0)
}

void complex::add (complex C1, complex C2) {
  real = C1.real + C2.real; 
  imag = C1.imag + C2.imag;
}

 

Home Up Next