LAB 1: OPERATOR OVERLOADING AND PROJECTS

DUE MONDAY, JAN 27, 3:00 pm

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

(You will also need to recall some of the topics from the first C++ course 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 (this file should be located in your class folder).

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-i 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).

You should write 3 different files under a project: One should be a header file for the complex number class, another one should be an implementation file for the complex number class and a third file with the main function.