Sunday, 24 July 2011

PROGRAM IN C++ to find the sum and difference of two given complex numbers

Do you like this post?
#include
#include
class complex
{
int ar;
int bi;
public:
complex()
{};
complex(int x)
{
ar=x;
bi=x;
}
complex(int x,int y)
{
ar=x;
bi=y;
}
complex add_complex(complex c2,complex c1)
{
complex c4;
c4.ar=c1.ar+c2.ar;
c4.bi=c1.bi+c2.bi;
return(c4);
}
void display()
{
cout<<"The sum of two given complex numbers is : "; cout<>x>>y;
cout<<"Enter the value of a(real part) and b(imaginary part) : "; cin>>a>>b;
complex c1(a,b);
complex c2(x,y);
c3=c1.add_complex(c2,c1);
c3.display();
c3=c1.sub_complex(c2,c1);
c3.put();
getch();
}

No comments:

Post a Comment