using System; public class Complex { 8: 81 8 private double rP; // real part private double iP; // imaginary part 3 refe
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am
using System; public class Complex { 8: 81 8 private double rP; // real part private double iP; // imaginary part 3 refe
1 reference public void mulfix (Complex cl) { // use the formula (a+bj) (c+dj) = (ac-bd) Cad+bc)j Complex ccopy = new Complex(); ccopy.rP = TP ccopy.ip = IP rP = ccopy.rP: ip = ccopy.ip; 3 references public void print() { cl.rp - ip * cl.ip; cl.ip + ip * cl.rp; Console.WriteLine("{0} + {1}j", rP, ip);
using System; O references public class Complex Test { 8 O references public static void Main(string[] args) { // create and initialize a Complex object Complex c1 = new Complex (), c2 = new Complex (), c3 = new Complex(); Console.WriteLine("Create 1+j"); cl.Set Complex (1, 1); Console.WriteLine("Print that"); 1-j"); Console.WriteLine("Create c2. Set Complex (1, -1); Console.WriteLine(" (1+j) (1-j) in the wrong way (correct answer is 2)"); cl.mul (c2); cl.add(c2); cl.print(); cl.print(); Console.WriteLine(" (1+j) (1-j) in the right way (correct answer is 2)"); cl.Set Complex (1, 1); cl.mulfix(c2); cl.print(
4. (39%) Enhance class Complex from week 4 (that has add, mulfix, etc.) or class Complex from week 5 (that has +-* as operators) (a) (5%) Method subtract (or operator -) to subtract two complex numbers (b) (10%) Method div (or operator /) to divide one complex number by another complex number va²+b² (c) (14%) Note that polar form of a complex number a +bj=re" with r of c, and argument or angle 8 as arctan (b/a) (are tangent of b/a). as the magnitude or the value (7%) Define method CarToPolar that convert a complex number of the Cartesian form a +bj to the polar form re" (7%) Define a second method Polar ToCar to convert a complex number of the polar form-re to its Cartesian form a +bj Note ar cos 0, and b-r sin( 0). (d) (10%) Test your enhanced class Complex with such test data: C1-1+1,C2-1-1 Compute C1+C2, C1-C2, C1 C2 and C1/C2 (division), Compute the polar form of C1, C2, and c Compute C1/0 (division by zero) and show if you have error messages (Note for 1-1, 1-2 and 45 degrees or a/4.) Note square root can be implemented using sqrt, and arctangent is implemented using atan or atan2 library functions 2