upsidedown

AMCHO PROGRAMMM!!!

Mar 2nd, 2012
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.75 KB | None | 0 0
  1. #include<iostream.h>
  2. class complex
  3. {
  4. public:
  5.     int real;
  6.     int img;
  7.     int sum;
  8.     complex()
  9.     {
  10.         real=0;
  11.         img=0;
  12.     }
  13.  
  14.  
  15. complex(int a,int b)
  16. {
  17.     real=a;
  18.     img=b;
  19. }
  20. complex(complex &x)
  21. {
  22.     real=x.real;
  23.     img=x.img;
  24. }
  25.  
  26. void getdata()
  27. {
  28.     cout<<"Enter real part\n";
  29.     cin>>real;
  30.     cout<<"Enter imaginary part\n";
  31.     cin>>img;
  32. }
  33.  
  34. void add(complex &x)
  35. {
  36.     real=real+x.real;
  37.     img=img+x.img;
  38.     cout<<"The addition is:\n";
  39.     cout<<"Real is "<<real<<endl;
  40.     cout<<"Imaginary is "<<img<<endl;
  41. }
  42. };
  43. int main()
  44. {
  45.     complex x;
  46.     x.getdata();
  47.     complex b;
  48.     b.getdata();
  49.     x.add(b);
  50.     return 0;
  51. }
  52.  
  53. Enter real part
  54. 2
  55. Enter imaginary part
  56. 4
  57. Enter real part
  58. 3
  59. Enter imaginary part
  60. 8
  61. The addition is:
  62. Real is 5
  63. Imaginary is 12
  64. Press any key to continue
Advertisement
Add Comment
Please, Sign In to add comment