CS 1401 Assignment #8

Date Assigned: Monday, March 19, or Tuesday, March 20, 2007.

Due Date: Monday, March 26, or Tuesday, March 27, 2007, before the beginning of your lab section.

Objective: The main objective of this assignment is to learn to design user-defined classes and ADTs.

Programming assignment: a complex number a + bi is characterized by its real part a and its imaginary part b. For complex numbers, the absolute value is defined as |a + bi| = sqrt(a^2 + b^2), a conjugate is defined as (a + bi)' = a - bi. Arithmetic operations are defined as follows:

(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
(a + ib)/(c + id) = (ac + bd)/(c^2 + d^2) + i(bc - ad)/(c^2 + d^2) if c + id =/= 0.

Describe a class whose elements are complex numbers, and methods include:

Use your class in the main program to create the number i (as 0 + 1i) and to check that i * i is indeed -1 (i.e., -1 + 0i).

Homework assignment: on a separate sheet of paper, solve Ex. 6 from p. 520 and Ex. 16 from p. 522.

Deliverables: as instructed by your TA.