Lab 8
Due: Tue, Apr 18, 11:59 pm
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.txt" from the class folder (P:\Class\Math\Aydin\118\FilesForLabs) 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.txt".
The file "inputdata.txt" contains 9 pairs of real (double) numbers.
Overload the binary operators +, *, >>, <<, and > as well as the unary operator - for the complex number class. For >, compare complex numbers on the basis of their moduli, i.e., if z1 and z2 are two complex numbers then z1 > z2 if and only if modulus of z1 > modulus of z2. The modulus of a complex number z = a+bi, which is also its distance to the origin, is defined as sqrt(a*a+b*b)
Read these numbers from inputdata.txt and create a complex number corresponding to each pair. Store these complex numbers in an array of complex numbers of size 10.
Ask for one more complex number from the user to store in the last entry of the array using the overloaded operator >>.
Print out (and send to the file as well) 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 -2 then it should be printed out as 1-2i rather than 1+-2i. If the imaginary part is + or -1, do not write 1. For instance instead of 2-1i, write 2-i. Also, if either (but noth both) part is 0, then do not write it out.
Print out the negatives of each one these complex numbers.
Find and print out the sum and product of all these 10 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.
Finally, sort these complex numbers in descending order according to their moduli (moduli is the plural of modulus) and print them in sorted order.
As usual, you will be graded on the following criteria: fulfillment of all requirements in problem statements, correct output, good user interface, good coding style and formatting. 150 pts.