LAB 10: OPERATOR OVERLOADING WITH COMPLEX NUMBERS

DUE THURSDAY, NOV 7, 9:00 am

In this lab we are going to practice operator overloading with complex numbers.

We will also be using some of the earlier concepts such as file input-output, formatting and sorting.

First, copy the file "inputdata.cpp" from the class folder into your own folder (and DO NOT modify this file).

All the output should be sent BOTH to the screen and to an output file which should be called outputdata.cpp.

The file "inputdata.cpp" contains 9 pairs of real (double) numbers.

Overload the binary operators +, *, >>, and << as well as the unary operator -

Read these numbers from inputdata.cpp and create a complex number corresponding to each pair. Store these complex numbers in an array (of complex numbers) of size 10.

Ask one more complex number from the user (to store in the last entry of the array) using the overloaded operator >>.

Print out each one of these complex numbers in a+bi form (use overloaded << operator to do that).

If the imaginary part is negative, there should be negative sign only. For example if a complex number has real part 1 and imaginary part -1 then it should be printed out as 1-1i rather than 1+-1i


Print out the negatives of each one these complex numbers.

Find and print out the sum and product of these complex numbers. Do necessary formatting so that the real and imaginary parts of sum and product have 2 places after the decimal point. Also print out the modulus of the sum and the modulus of the product.

Sort these complex numbers in descending order according to their moduli (moduli is the plural of modulus).