Advertisement
steverobinson

Steve Robinson

Aug 18th, 2010
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.62 KB | None | 0 0
  1. //Binary - Overloading
  2.  
  3. #include <iostream.h>
  4.  
  5. class complex
  6. {
  7.     int real, imag;
  8.     public:
  9.         complex(int tr,int ti)
  10.         {
  11.             real=tr;
  12.             imag=ti;
  13.         }
  14.         complex(){}
  15.         void display()
  16.         {
  17.             cout<<"\nComplex Number = "<<real<<"+i"<<imag;
  18.         }
  19.         friend complex operator -(complex c1, complex c2);
  20.  
  21. };
  22.  
  23. complex operator -(complex c1, complex c2)
  24. {
  25.     complex result;
  26.     result.real=c1.real-c2.real;
  27.     result.imag=c1.imag-c2.imag;
  28.     return result;
  29. }
  30. int main()
  31. {
  32.     complex c1(10,20),c2(5,10);
  33.     c1.display();
  34.     c2.display();
  35.     cout<<"\nResult after Subtraction:\n";
  36.     complex result=c1-c2;
  37.     result.display();
  38.     return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement