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
.

Write a constructor with two parameters, copy constructor, add member function, subtract member function, divide member function, multiply member function, and destructor.

Use these formulas:

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

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

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

Complex divide(const Complex &) : (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 constructors, math member functions, and destructor for class
Complex
.

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
Test the constructor with two parameters.
Complex number c1 is: (1.1+2.3i)
Test the copy constructor.
Complex number c2 is: (1.1+2.3i)
Test the add() member function.
Destructor for: (2.2 + 4.6i)
(1.1+2.3i) + (1.1+2.3i) = (2.2+4.6i)
Test the subtract() member function:
Destructor for: (0 + 0i)
(1.1+2.3i)  (1.1+2.3i) = (0+0i)
Test the multiply() member function:
Destructor for: (4.08 + 5.06i)
(1.1+2.3i) * (1.1+2.3i) = (4.08+5.06i)
Test the divide member function:
Destructor for: (1 + 0i)
(1.1+2.3i) / (1.1+2.3i) = (1+0i)
Destructor for: (1 + 0i)
Destructor for: (1.1 + 2.3i)
Destructor for: (1.1 + 2.3i)
Click to validate the HTML code
Click to validate the CSS code