Write a program (calculation.ccp) to allow the user to perform an arithmetic operation on the two complex numbers entered. The user can key in one of the four operations: addition (+), subtraction (-), multiplication (*) and division (/). Overload the operators to meet the requirements as stated below.
To sum two complex numbers, you have to sum the real and imaginary parts separately.
E.g. (4 + 5i) + (3 + 2i) = (4+3) + (5+2)i = 7 + 7i.
To subtract one complex number from another, you have to subtract the real and imaginary parts separately.
E.g. (4 + 5i) - (3 + 2i) = (4-3) + (5-2)i = 1 + 3i .
To multiply two complex numbers, please use the following formula.
(a + bi) x (c + di) = ac + adi + bci - bd = (ac - bd) + (ad + bc)i
E.g. (4 + 5i) * (3 + 2i) = (12-10) + (8 + 15)i = 2 + 23i
To divide one complex number with another complex number, multiply the numerator and the denominator by the conjugate of the denominator.
(a + bi) / (c + di) = [(a + bi) * (c - di)] / [(c + di) * (c - di)]
E.g. (4 + 5i) / (3 + 2i) = [(4 + 5i) * (3 - 2i)] / [(3 + 2i) * (3 - 2i)] = (12 + 7i + 10) / (9+4)
= (22 + 7i) / 13
Your program shall perform the following:
1. Prompt user to enter the first number, an operator and the second number. The program should print out the result of the operation.
2. The program shall catch multiple exceptions by implementing try and catch blocks
3. The program should be able to tackle the following exceptions:
a. If the user types an invalid operator, the program should be able to detect that and the catch block should be able to display a message: an invalid operator.
b. If the user types in an invalid number (i.e. anything apart from a character from 0 to 9), the program should throw an error and the catch block should be able to display a message: an invalid numeric number.
c. If the user enters a forward slash ''/" to perform a division, the program should check to see if the second number is a 0. The denominator should not be a 0. If it is, the program presents a throw that sends a complex number. The program will implement another catch that takes the complex number as an argument. It will display a message: division by 0 is not allowed.
4. The program requires you to test the overloading operators to check if you get the same output as given by the examples above.