Assignment Instructions

  1. Edit, compile, and run the following program on the UH UNIX shell:
    1. Create a class called Complex for performing arithmetic with complex numbers.
    2. 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.
    3. The data members, real and imaginary, should be data type double.
    4. In the constructor, initialize real and imaginary to zero (0).
    5. Write one print() function that outputs the complex number in the format: a + bi
    6. Write one set() method that sets both real and imaginary.
    7. Write two get() methods (getReal() and getImaginary()) that return the values real or imaginary.
    8. In the driver program (main() function), create at least three (3) complex numbers and test all of the member functions for class Complex.
    9. Email your makefile and C program to the instructor, or show it to the instructor in class.
  2. For the submission guidelines and the grading guidelines, see the syllabus.

Example I/O

Test the constructor.
Complex number c1 is: 0 + 0i

Test the one set() function.
Complex number c2 is: 3.3 + 4.4i

Test the two get() functions.
Complex number c3's real part is: 5.5
Complex number c3's imaginary part is: 6.6

Click to validate the HTML code

Click to validate the CSS code