Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream.h>
- class complex
- {
- public:
- int real;
- int img;
- int sum;
- complex()
- {
- real=0;
- img=0;
- }
- complex(int a,int b)
- {
- real=a;
- img=b;
- }
- complex(complex &x)
- {
- real=x.real;
- img=x.img;
- }
- void getdata()
- {
- cout<<"Enter real part\n";
- cin>>real;
- cout<<"Enter imaginary part\n";
- cin>>img;
- }
- void add(complex &x)
- {
- real=real+x.real;
- img=img+x.img;
- cout<<"The addition is:\n";
- cout<<"Real is "<<real<<endl;
- cout<<"Imaginary is "<<img<<endl;
- }
- };
- int main()
- {
- complex x;
- x.getdata();
- complex b;
- b.getdata();
- x.add(b);
- return 0;
- }
- Enter real part
- 2
- Enter imaginary part
- 4
- Enter real part
- 3
- Enter imaginary part
- 8
- The addition is:
- Real is 5
- Imaginary is 12
- Press any key to continue
Advertisement
Add Comment
Please, Sign In to add comment