upsidedown

oops exp5 r.p

Mar 2nd, 2012
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.29 KB | None | 0 0
  1. #include<iostream.h>
  2. class complex1;
  3. class complex
  4. {
  5.     int re,img;
  6. public:
  7.     complex()
  8.     {
  9.         re=0;
  10.         img=0;
  11.     }
  12.  
  13.     complex(int x=1,int y=1)
  14.     {
  15.         re=x;
  16.         img=y;
  17.     }
  18.  
  19.     ~complex()
  20.     {
  21.         cout<<"deleted objects of class complex\n";
  22.     }
  23.  
  24.     friend void add(complex,complex1);
  25. };
  26.  
  27. class complex1
  28. {
  29.     int re1,img1;
  30. public:
  31.     complex1()
  32.     {
  33.         re1=0;
  34.         img1=0;
  35.     }
  36.  
  37.     complex1(int x=6,int y=6)
  38.     {
  39.         re1=x;
  40.         img1=y;
  41.     }
  42.  
  43.     complex1(complex1 &x)
  44.     {
  45.         re1=x.re1;
  46.         img1=x.img1;
  47.     }
  48.  
  49.     ~complex1()
  50.     {
  51.         cout<<"deleted objects of class complex1\n";
  52.     }
  53.  
  54.     friend void add(complex,complex1);
  55. };
  56.  
  57. void add(complex a,complex1 b)
  58. {
  59.     cout<<"the addition of ("<<a.re<<")+i("<<a.img<<")  +  ("<<b.re1<<")+i("<<b.img1;
  60.     cout<<") = ("<<(a.re+b.re1)<<")+i("<<(a.img+b.img1)<<")\n";
  61. }
  62.  
  63. int main()
  64. {
  65.     int a,b,c,d;
  66.     cout<<"addition of two complex nos:\n";
  67.     cout<<"enter the real and imaginary values of 1st number:\n";
  68.     cout<<"real part= ";
  69.     cin>>a;
  70.     cout<<"complex part= ";
  71.     cin>>b;
  72.     cout<<"enter the real and imaginary values of 2st number:\n";
  73.     cout<<"real part= ";
  74.     cin>>c;
  75.     cout<<"complex part= ";
  76.     cin>>d;
  77.     complex x(a,b),y(x);
  78.     complex1 p(c,d),q(c);
  79.     cout<<"using parameterized constructors\n";
  80.     add(x,p);
  81.     cout<<"using copy and default construction\n";
  82.     add(y,q);
  83.     return 0;
  84. }
Advertisement
Add Comment
Please, Sign In to add comment