#include<iostream.h>
#include<conio.h>
class Complex
{
public:
int r;
int im;
Complex()
{
r=0;
im=0;
}
void get();
void show();
friend Complex operator + (Complex &a, Complex &b);
};
void Complex :: get()
{
cout<<"Enter the value of x and y in the form of x + iy "<<endl;
cin>>r>>im;
}
void Complex :: show()
{
cout<<r<<" + "<<im<<"i"<<endl;
}
Complex operator + (Complex &ob1,Complex &ob2)
{
Complex temp1;
temp1.r=ob1.r + ob2.r;
temp1.im=ob1.im + ob2.im;
return(temp1);
}
void main()
{
Complex c1,c2,c3;
c1.get();
c2.get();
c3=c1+c2;
c3.show();
getch();
}
OUTPUT
#include<conio.h>
class Complex
{
public:
int r;
int im;
Complex()
{
r=0;
im=0;
}
void get();
void show();
friend Complex operator + (Complex &a, Complex &b);
};
void Complex :: get()
{
cout<<"Enter the value of x and y in the form of x + iy "<<endl;
cin>>r>>im;
}
void Complex :: show()
{
cout<<r<<" + "<<im<<"i"<<endl;
}
Complex operator + (Complex &ob1,Complex &ob2)
{
Complex temp1;
temp1.r=ob1.r + ob2.r;
temp1.im=ob1.im + ob2.im;
return(temp1);
}
void main()
{
Complex c1,c2,c3;
c1.get();
c2.get();
c3=c1+c2;
c3.show();
getch();
}
OUTPUT
No comments:
Post a Comment