addition and multiplication on complex no
code :
#include
using namespace std;
class complex
{
private:
float a,b;
public:
complex()
{
a = 0.0;
b = 0.0;
}
void getdata()
{
cout<<"Enter real part of complex number :";
cin>>a;
cout<<"Enter imaginary part of complex number :";
cin>>b;
}
void putdata()
{
if (b>0)
{
cout<}
else
{
cout<}
}
complex operator +(complex c)
{
complex x;
x.a = a + c.a;
x.b = b + c.b;
return x;
}
complex operator *(complex c)
{
complex x;
x.a = (a*c.a) - (b*c.b);
x.b = (a*c.b) + (c.a*b);
return x;
}
};
int main()
{
complex c1,c2,c3,c4;
cout<<"For first complex number : ";
c1.getdata();
cout<<"For second complex number : ";
c2.getdata();
c3 = c1 + c2;
c4 = c1 * c2;
cout<<" First complex number = ";
c1.putdata();
cout<<" Second complex number = ";
c2.putdata();
cout<<"_________________________________________________"<
c3.putdata();
cout<<"_________________________________________________"<
c4.putdata();
return 0;
}
No comments:
Post a Comment