#include <iostream.h>
class Complex{
public:
Complex()
{
real=0;
imag=0;
}
Complex(double r,double i)
{
real=r;
imag=i;
}
Complex operator +(Complex &);
Complex operator +(int &);
friend Complex operator +(int &,Complex &);
void display()
{
cout<<"("<<real<<"+"<<imag<<"i)"<<endl;
}
private:
double real;
double imag;
};
Complex Complex::operator +(Complex &c2)
{
return Complex(real+c2.real,imag+c2.imag);
}
Complex Complex::operator +(int &i)
{
return Complex(real+i,imag);
}
Complex operator +(int &i,Complex &c3)
{
return Complex(i+c3.real,c3.imag);
}
int main()
{
int i=2;
Complex c1(2,4),c2(1,2),c3,c4,c5;
c3=c1+c2;
cout<<"c3=c1+c2=";
c3.display();
c4=c1+i;
cout<<"c4=c1+i=";
c4.display();
c5=i+c2;
cout<<"c5=i+c2=";
c5.display();
return 0;
}