CJCoding With Joseph
15free / daySign inCreate account

Complex Add and Stream Print (operator+ and operator<<)

You want to add complex numbers and print them cleanly.

Create a class Complex2 with ints real and imag.

Requirements:
1) Constructor Complex2(int r, int i)
2) operator+ returns NEW Complex2 by adding parts
3) operator<< prints as: a+bi or a-bi (no spaces)
   Examples: 3+4i, 5-2i

Do NOT write a main function.

Expected Output:

3+4i
5-2i

= newline. The output ends with a newline — print one after the last line.

Hints4 available
Topics:
ClassesOperator Overloading
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (cout, fori)

Your Output

Run your code to see the output here...

Test Cases

Run your code to see test case results.