Assignment Instructions

Edit, compile, and run the following program on the UH UNIX shell:

Create a class called
Complex
for performing arithmetic with complex numbers.

Complex numbers have the form
a + bi
, where a
is the real part, b
is the imaginary part,
and i
is the square root of negative one.

The data members,
real
and imaginary
, should be data type double
.

Overload the following operators: >> (for cin), << (for cout), +, , *, /, ==, and !=.

Since we are overloading the >> operator (for cin), we need to test this operator by asking the user to input complex numbers. See the example output below, where the program is asking the user to "Enter a Complex number in the form 'a+bi'". In the main() function, prompt the user to enter two complex numbers. Your >> operator definition should be able to read a double, read the character '+', read another double, and then read the character 'i'. In other words, it should be able to read a complex number in this format: a+bi.

For the overloaded operator functions for == and !=,
the return type should be bool,
and return value should be true or false.
Here is an example of the bool data type:
bool.cpp

Use these formulas:

add: (a + bi) + (c + di) = (a + c) + (b + d)i

subtract: (a + bi)  (c + di) = (a  c) + (b  d)i

multiply: (a + bi) * (c + di) = (a*c  b*d) + (b*c + a*d)i

divide: (a + bi) / (c + di) = (a*c + b*d)/(c*c + d*d) + (b*c  a*d)/(c*c + d*d)i

In the driver program (main() function), create at least three (3) complex numbers
and test all of the overloaded operators for class
Complex
.

Do NOT use the
print()
method to output complex numbers.
Instead, use the overloaded cout<<
method.

Email your makefile and C program to the instructor, or show it to the instructor in class.

For the submission guidelines and the grading guidelines, see the syllabus.
Example I/O
Enter a Complex number in the form 'a+bi': 3+4i
Enter another Complex number in the form 'a+bi': 3+5i
Test the + operator:
3+4i + 3+5i = 6+9i
Test the  operator:
3+4i  3+5i = 01i
Test the * operator:
3+4i * 3+5i = 11+27i
Test the / operator:
3+4i / 3+5i = 0.8529410.0882353i
Test the == operator:
3+4i == 3+5i = false
Test the != operator:
3+4i != 3+5i = true
Click to validate the HTML code
Click to validate the CSS code