C++ complex number addition (operator overloading)
Submissions: 465   Accuracy:

59.08%

  Difficulty: Easy   Marks: 2

This is a functional problem i.e. partial code is already done for you, invest time to study the locked code and complete the solution accordingly.

In this problem, you need to add 2 given complex numbers and print the resulting complex number using '+' operator.

Implement a class named complex containing data members as real and imaginary part of the complex number and the following function:

  • void display()
  • constructor to assign values to the complex number.
  • operator function to add 2 numbers

Input:

First line of the input contains the number of test cases and each test case contains 4 space separated integer values representing the real and imaginary part of 2 complex numbers ( Real1 imaginary 1   real2 imaginary2 )
Output:

The output to each test case should be a single line representing the resulting complex number from the addition of given complex numbers. In the given format

real + imaginary_i

for eg:  2 +3i
Constraints:

1 <= Test case <= 100
Example:

Input:

2

3 6 -1 4

2 2 -1 -1

Output:

2 + 10i
1 + 1i

 

 

** For More Input/Output Examples Use 'Expected Output' option **

Author: Archit18_PEC


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.


to report an issue on this page.