Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream.h>
- #include<conio.h>
- class Complex
- {
- double real;
- double imag;
- public:
- Complex()
- {
- real=1;
- imag=1;
- cout<<"Default Constructor called"<<endl;
- }
- Complex(int r, int i)
- {
- real=r;
- imag=i;
- cout<<"Parameterized Constructor called"<<endl;
- }
- void display()
- {
- cout<<"Complex number is"<<endl;
- cout<<real<<"+"<<imag<<"i"<<endl;
- }
- Complex operator+(Complex);
- };
- Complex Complex::operator+(Complex other)
- { Complex result;
- result.real = real + other.real;
- result.imag = imag + other.imag;
- return result;
- }
- void main()
- {
- clrscr();
- Complex x,y(2,3),z;
- x.display();
- y.display();
- z=x+y;
- z.display();
- getch();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement