โ Back to Classes
Question 81
Complex Add and Stream Print (operator+ and operator<<)
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
Topics:
ClassesOperator Overloading
Code Editor
1
Tab to indent ยท Ctrl+Enter to run ยท 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.