Advertisement
varungurnaney

HSC: Addition of Complex numbers(medium)

Feb 7th, 2015
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.71 KB | None | 0 0
  1. #include<iostream.h>
  2. #include<conio.h>
  3.  
  4. class Complex
  5. {
  6. double real;
  7. double imag;
  8. public:
  9.     Complex()
  10.         {
  11.         real=1;
  12.         imag=1;
  13.         cout<<"Default Constructor called"<<endl;
  14.         }
  15.  
  16.     Complex(int r, int i)
  17.         {
  18.         real=r;
  19.         imag=i;
  20.         cout<<"Parameterized Constructor called"<<endl;
  21.    
  22.         }
  23.  
  24.         void display()
  25.         {
  26.         cout<<"Complex number is"<<endl;
  27.         cout<<real<<"+"<<imag<<"i"<<endl;
  28.         }
  29.     Complex operator+(Complex);
  30.  
  31.  
  32. };
  33.  
  34. Complex Complex::operator+(Complex other)
  35. {   Complex result;
  36.     result.real = real + other.real;
  37.     result.imag = imag + other.imag;
  38.     return result;
  39. }
  40.  
  41.  
  42. void main()
  43. {
  44. clrscr();
  45. Complex x,y(2,3),z;
  46. x.display();
  47. y.display();
  48. z=x+y;
  49. z.display();
  50. getch();
  51.  
  52.  
  53.  
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement