Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Binary - Overloading
- #include <iostream.h>
- class complex
- {
- int real, imag;
- public:
- complex(int tr,int ti)
- {
- real=tr;
- imag=ti;
- }
- complex(){}
- void display()
- {
- cout<<"\nComplex Number = "<<real<<"+i"<<imag;
- }
- friend complex operator -(complex c1, complex c2);
- };
- complex operator -(complex c1, complex c2)
- {
- complex result;
- result.real=c1.real-c2.real;
- result.imag=c1.imag-c2.imag;
- return result;
- }
- int main()
- {
- complex c1(10,20),c2(5,10);
- c1.display();
- c2.display();
- cout<<"\nResult after Subtraction:\n";
- complex result=c1-c2;
- result.display();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement