In this HackerRank Overload Operators problem in c++ You need to overload operators + and << for the Complex class.

HackerRank Overload Operators in C++ problem solution

HackerRank Overload Operators in C++ problem solution

//Overload operators + and << for the class complex
//+ should add two complex numbers as (a+ib) + (c+id) = (a+c) + i(b+d)
//<< should print a complex number in the format "a+ib"

Complex operator+(const Complex &lhs, const Complex &rhs)
{
    return { lhs.a + rhs.a, lhs.b + rhs.b };
}

ostream &operator<<(ostream &is, const Complex &rhs)
{
    is << rhs.a << "+i" << rhs.b;
    return is;
}