When a class is defined, its objects can interact with each other through the operators, but it is necessary to define the behavior of these operators through operator overloading.
We are going to implement a class that represents a complex number.“ A complex number consists of a real part and an imaginary part.
When we add a complex number, the real part is added to the real part, and the imaginary part is added to the imaginary part.
Similarly, when we subtract a complex number, the real part is subtracted from the real part, and the imaginary part is subtracted from the imaginary part.
An example of this is shown below:
a=3+7i
b=2+5i
a+b=(3+2)+(7+5)i=5+12i
�
a−b=(3−2)+(7−5)i=1+2i
Now, let’s implement the complex number class and overload the + and - operators below: