Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
Write a program similar to the one shown in Figure 23-3 to manipulate complex numbers. When you enter the complex numbers' real and imaginary parts in the textboxes and click Calculate, the program should display the sum, difference, and product of the two complex numbers.
Make a ComplexNumber class with properties Real and Imaginary to hold a number's real and imaginary parts. Give the class AddTo, MultiplyBy, and SubtractFrom methods that combine the current ComplexNumber with another taken as a parameter and return the result as a new ComplexNumber.
Hints: Recall from school these equations for calculating with 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
For more review of complex numbers, see en.wikipedia.org/wiki/Complex_numbers or mathworld.wolfram.com/ComplexNumber.html.
NOTE
You can download the solution to this exercise from the book's web page at www.wrox.com or www.CSharpHelper.com/24hour.html. You can find this solution in the Lesson23 folder.