Topical Information

This lab will help you practice with classes.

Program Information

Design and code a class for a complex number ADT. To refresh your memory, complex numbers have the form: a+bi. Where a is the real part, b is the imaginary part, and i represents the square root of -1 (which doesn't exist and is therefore imaginary).

Standard mathematical operations are defined on complex numbers:

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

    a+bi - c+di = (a-c) + (b-d)i

    a+bi * c+di = (a*c-b*d) + (a*d+b*c)i    // i*i == -1

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

And special operations are also defined:

              ___________
   |a+bi| = \/ a*a + b*b                       // magnitude

    ____
    a+bi  = a-bi                               // conjugate

Define these operations (along with construction, input/output, and access/mutation) for your ADT class. Place your ADT in a library. (You may find the notes elsewhere on the site somewhat helpful.)

Write a driver to test the ADT's operations.

Thought Provoking Questions

  1. Why do your class methods take fewer arguments than you might/would expect?

  2. Does your addition method change the value of the calling object? Should it? Does the compiler change x when you have x+y in your program? What about y? Does/Should your addition method change the other complex number? Does this extend to the other operations? How do you tell the compiler about your decisions?

  3. What kind of value should be returned from the standard math operations (i.e. what TYPE of value)? From conjugate? From magnitude?

  4. Does your input method prompt the user? Why shouldn't it?

  5. Does your output method print anything besides the complex number (using proper notation) — even an endl? Why shouldn't it?

This assignment is (Level 5).

Options