C/C++ code#include
using namespace std;
class ComplexNum
{
private:
int real;
int imaginary;
public:
ComplexNum()
{
this->real=0;
this->imaginary=0;
}
ComplexNum(int real,int imaginary)
{
this->real=real;
this->imaginary=imaginary;
}
int getReal()
{
return this->real;
}
void setReal(int real)
{
this->real=real;
}
void setImaginary(int imaginary)
{
this->imaginary=imaginary;
}
int getImaginary()
{
return this->imaginary;
}
ComplexNum operator+(ComplexNum &x)
{
ComplexNum y;
y.setReal(this->real+x.real);
y.setImaginary(this->imaginary+x.imaginary);
return y;
}
ComplexNum operator-(ComplexNum &x)
{
ComplexNum y;
y.setReal(this->real-x.real);
y.setImaginary(this->imaginary-x.imaginary);
return y;
}
ComplexNum operator*(ComplexNum &x)
{
ComplexNum y;
y.setReal(this->real*x.real-this->imaginary*x.imaginary);
y.setImaginary(this->imaginary*x.real+this->real*x.imaginary);
return y;
}
friend ostream&operator<
{
if(x.getImaginary()==0)
return cout<
else if(x.getImaginary()<0)
return cout<
else if(x.getImaginary()>0)
return cout<
return cout<
}
};
void main()
{
ComplexNum c1(10,5);
ComplexNum c2(3,7);
ComplexNum c3(0,0);
cout<
cout<
cout<
cout<
cout<
}