Paste Search Dynamic
Recent pastes
complex
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class complex{
  5. public:
  6.         complex(double =0, double=0);
  7.         void add(complex &);
  8.     void sub(complex &);
  9.         void print();
  10. private:
  11.         double realPart;
  12.         double imagPart;
  13. };
  14. complex::complex(double x1, double x2)
  15. {       realPart=x1;
  16.         imagPart=x2;           
  17. }
  18.  
  19. void complex::add (complex & a)
  20. {       realPart+=a.realPart ;
  21.         imagPart+=a.imagPart ;
  22. }
  23.  
  24. void complex::sub (complex & a)
  25. {       realPart-=a.realPart ;
  26.         imagPart-=a.imagPart ;
  27. }
  28.  
  29. void complex::print ()
  30. {       cout<<"["<<realPart<<", "<<imagPart<<" * i"<<"]"<<endl;
  31. }
  32.  
  33.  
  34.  
  35.  
  36. int main() {
  37.  
  38.    complex n1(2, 5);
  39.         complex n2(3, 4);
  40.         complex n3(1, 3);
  41.         cout<<"complex numbers are: n";
  42.         n1.print();
  43.         n2.print();
  44.         n3.print();
  45.     n1.add (n2);
  46.     n2.sub (n3);
  47.         cout<<" complex addition of number1 and number2 is:n";
  48.     n1.print ();
  49.     cout<<" complex subtraction of number 2 and number3 is :n";
  50.     n2.print ();
  51.  
  52.         return 0;
  53. }
Parsed in 0.005 seconds