#include <iostream>
using namespace std;
class Complex
{
public:
Complex(){real=0;imag=0;}
Complex(double r,double i){real=r;imag=i;}
Complex operator+(const Complex &c2);
void display();
private:
double real,imag;
};
Complex Complex::operator+(const Complex &c2)
{
return Complex(real+c2.real,imag+c2.imag);
}
void Complex::display()
{
if(imag<0){
cout<<real<<"i"<<imag<<endl;
}
else
{
cout<<real<<"i"<<"+"<<imag<<endl;
}
}
int main()
{
Complex c1(1,2),c2(1,1),c3;
c3=c1+c2;
c3.display();
return 0;
}
using namespace std;
class Complex
{
public:
Complex(){real=0;imag=0;}
Complex(double r,double i){real=r;imag=i;}
Complex operator+(const Complex &c2);
void display();
private:
double real,imag;
};
Complex Complex::operator+(const Complex &c2)
{
return Complex(real+c2.real,imag+c2.imag);
}
void Complex::display()
{
if(imag<0){
cout<<real<<"i"<<imag<<endl;
}
else
{
cout<<real<<"i"<<"+"<<imag<<endl;
}
}
int main()
{
Complex c1(1,2),c2(1,1),c3;
c3=c1+c2;
c3.display();
return 0;
}