Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream.h>
- class complex1;
- class complex
- {
- int re,img;
- public:
- complex()
- {
- re=0;
- img=0;
- }
- complex(int x=1,int y=1)
- {
- re=x;
- img=y;
- }
- ~complex()
- {
- cout<<"deleted objects of class complex\n";
- }
- friend void add(complex,complex1);
- };
- class complex1
- {
- int re1,img1;
- public:
- complex1()
- {
- re1=0;
- img1=0;
- }
- complex1(int x=6,int y=6)
- {
- re1=x;
- img1=y;
- }
- complex1(complex1 &x)
- {
- re1=x.re1;
- img1=x.img1;
- }
- ~complex1()
- {
- cout<<"deleted objects of class complex1\n";
- }
- friend void add(complex,complex1);
- };
- void add(complex a,complex1 b)
- {
- cout<<"the addition of ("<<a.re<<")+i("<<a.img<<") + ("<<b.re1<<")+i("<<b.img1;
- cout<<") = ("<<(a.re+b.re1)<<")+i("<<(a.img+b.img1)<<")\n";
- }
- int main()
- {
- int a,b,c,d;
- cout<<"addition of two complex nos:\n";
- cout<<"enter the real and imaginary values of 1st number:\n";
- cout<<"real part= ";
- cin>>a;
- cout<<"complex part= ";
- cin>>b;
- cout<<"enter the real and imaginary values of 2st number:\n";
- cout<<"real part= ";
- cin>>c;
- cout<<"complex part= ";
- cin>>d;
- complex x(a,b),y(x);
- complex1 p(c,d),q(c);
- cout<<"using parameterized constructors\n";
- add(x,p);
- cout<<"using copy and default construction\n";
- add(y,q);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment