(a + bi) + (c + di) = (a + c) + (b + d)i
(a + bi) - (c + di) = (a - c) + (b - d)i
(a + bi) * (c + di) = (ac - bd) + (ad + bc)i
(a + bi) / (c + di) = ( (ac + bd) / (c2 + d2) ) + ((bc - ad) / (c2 + d2)) i
provided that c and d are not both 0 in the case of division. The program should allow the user to continue entering complex numbers until she/he chooses to quit.
Use the following subroutine when printing the results:
SUBROUTINE Print_Complex (Real_A, Im_A, Real_B, Im_B, Real_X,
Im_X, Operation)
! This subroutine will print out the result of the
complex calculation
! Pre-condition : variables Real_A, Im_A, Real_B,
Im_B, Real_X, Im_X, Operation are defined
! Post-condition: A line giving the two input complex numbers,
the operation, and the result are printed.
REAL INTENT(IN) :: Real_A, Im_A, Real_B,
Im_B, Real_X, Im_X
CHARACTER(1) :: Operation
PRINT 20, Real_A, Im_A, Operation, Real_B,
Im_B, Real_X, Im_X
20 FORMAT ( 1x, " ( ", F7.2,
" + ", F7.2, "i ) ", A1, " ( ", F7.2, " + ", F7.2, "i ) =
( ", F7.2, " + ", F7.2, "i ) " )
END SUBROUTINE Print_Complex
So that your output looks similar to that shown in the sample execution, i.e., ( 2.10 + 4.70i) * ( 6.00 + -8.40i) = 52.08 + 10.56i The input to this subroutine are six real numbers that are the real and imaginary parts of the two given complex numbers and the calculated results. The last argument is a character that is "+", "-", "*", or "/" depending on the operation that the user has selected.
Your program must also include one function of type LOGICAL. The function should return the value .TRUE. if both c and d (as given in the equations above) equal zero, .FALSE. otherwise.
In the main program, your selection structure should be set up like this:
IF the user chooses addition THEN
add the two complex numbers
ELSE IF the user chooses subtraction THEN
subtract the two complex
numbers
ELSE IF the user chooses multiplication THEN
multiply the two complex
numbers
ELSE IF the user chooses division THEN
IF denominators are O.K.
THEN
divide
the two complex numbers
ELSE
print
``zero denominator'' message
ENDIF
ENDIF
COMPLEX NUMBER CALCULATOR You will be asked to enter two complex numbers of the form a + bi. For each complex number, your input will be the pair of real numbers a and b. After entering the complex numbers, you will be asked to choose from a menu of arithmetic operations. Enter first complex number as a pair of real numbers (separate your two values with a space) 2.1 4.7 Enter second complex number as a pair of real numbers (separate your two values with a space) 6 -8.4 Which operation would you like to perform? Type: A to add S to subtract M to multiply D to divide What is your choice? q Sorry, you have entered an invalid choice What is your choice? (A, S, M, or D) m You have chosen to multiply the complex numbers ( 2.10 + 4.70i) * ( 6.00 + -8.40i) = 52.08 + 10.56i Would you like to enter another pair? n program terminating... %exit exit