The System.Numerics namespace has included the Complex structure to represent complex numbers since C# 4.0. Building something similar demonstrates so many useful techniques that it's still worth creating your own version. For this problem, create a ComplexNumber structure that has the following features:
- Re and Im properties that get and set the number's real and imaginary parts
- A FromPolar factory method that creates a ComplexNumber from a polar coordinate representation
- Static values representing 0, 1, and i
- ToString and Parse methods that translate a value to and from a string with the format x + yi
- Implementation of the IEquatable interface
- An overloaded Equals method that determines whether two values are equal with a given precision
- Read-only Magnitude and Angle properties to get the number's polar coordinate representation
- Operators that convert from a double implicitly and to a double explicitly
- Arithmetic operators that let you perform addition, subtraction, multiplication, division, and negation with ComplexNumber and numeric values
A factory method is a method that creates an instance of a class. Usually, it is a static method, so you don't need an instance of the class to invoke it. In this problem, the FromPolar method should take the polar coordinates r and θ as parameters and return an appropriate new ComplexNumber structure.
If you are unfamiliar with complex numbers or with their polar representation, see en.wikipedia.org/wiki/Complex_number or http://mathworld.wolfram.com/ComplexNumber.html, or search the web for Complex Numbers.
If you are unfamiliar with complex numbers or with their polar representation, see en.wikipedia.org/wiki/Complex_number or http://mathworld.wolfram.com/ComplexNumber.html, or search the web for Complex Numbers.
Hint: Use the following equation to divide two complex numbers:
Write a test program that verifies the ComplexNumber class's features.