Advertisement
varungurnaney

MPSTME: Add Complex number using Friend function

Feb 25th, 2015
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.39 KB | None | 0 0
  1. #include<iostream.h>
  2. #include<conio.h>
  3.  
  4. class complex
  5. {
  6. int real,img;
  7. public:
  8. complex(int x,int y)
  9. {
  10.     real=x;
  11.     img=y;
  12.     cout<<real<<" + i"<<img<<endl;
  13. }
  14. friend void add(complex,complex);
  15. };
  16.  
  17. void add(complex q,complex w)
  18. {
  19.     int real=q.real+w.real;
  20.     int img=q.img+w.img;
  21.     cout<<real<<" + i"<<img<<endl;
  22. }
  23. void main()
  24. {
  25. clrscr();
  26. complex a(9,1),b(1,2);
  27. add(a,b);
  28. getch();
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement