예제 #1
0
 public ComplexNumber Divide(ComplexNumber n1, ComplexNumber n2)
 {
     ComplexNumber conjugate = new ComplexNumber(n2.Real, -1*n2.Imaginary);
     ComplexNumber numerator = Multiply(n1, conjugate);
     ComplexNumber denominator = Multiply(n2, conjugate);
     return new ComplexNumber(numerator.Real / denominator.Real, numerator.Imaginary);
 }
예제 #2
0
 public ComplexNumber Multiply(ComplexNumber n1, ComplexNumber n2)
 {
     double real1 = n1.Real * n2.Real;
     double imaginary1 = n1.Real * n2.Imaginary;
     double imaginary2 = n2.Real * n1.Imaginary;
     double real2 = n1.Imaginary * n2.Imaginary * -1;
     return new ComplexNumber(real1 + real2, imaginary1 + imaginary2);
 }
예제 #3
0
        static void Main()
        {
            // Create a client
            DataContractCalculatorClient client = new DataContractCalculatorClient();

            // Call the Add service operation.
            ComplexNumber value1 = new ComplexNumber(); value1.Real = 1; value1.Imaginary = 2;
            ComplexNumber value2 = new ComplexNumber(); value2.Real = 3; value2.Imaginary = 4;
            ComplexNumber result = client.Add(value1, value2);
            Console.WriteLine("Add({0} + {1}i, {2} + {3}i) = {4} + {5}i",
                value1.Real, value1.Imaginary, value2.Real, value2.Imaginary, result.Real, result.Imaginary);
            // Call the Subtract service operation.
            value1 = new ComplexNumber(); value1.Real = 1; value1.Imaginary = 2;
            value2 = new ComplexNumber(); value2.Real = 3; value2.Imaginary = 4;
            result = client.Subtract(value1, value2);
            Console.WriteLine("Subtract({0} + {1}i, {2} + {3}i) = {4} + {5}i",
                value1.Real, value1.Imaginary, value2.Real, value2.Imaginary, result.Real, result.Imaginary);

            // Call the Multiply service operation.
            value1 = new ComplexNumber(); value1.Real = 2; value1.Imaginary = 3;
            value2 = new ComplexNumber(); value2.Real = 4; value2.Imaginary = 7;
            result = client.Multiply(value1, value2);
            Console.WriteLine("Multiply({0} + {1}i, {2} + {3}i) = {4} + {5}i",
                value1.Real, value1.Imaginary, value2.Real, value2.Imaginary, result.Real, result.Imaginary);

            // Call the Divide service operation.
            value1 = new ComplexNumber(); value1.Real = 3; value1.Imaginary = 7;
            value2 = new ComplexNumber(); value2.Real = 5; value2.Imaginary = -2;
            result = client.Divide(value1, value2);
            Console.WriteLine("Divide({0} + {1}i, {2} + {3}i) = {4} + {5}i",
                value1.Real, value1.Imaginary, value2.Real, value2.Imaginary, result.Real, result.Imaginary);

            //Closing the client gracefully closes the connection and cleans up resources
            client.Close();

            Console.WriteLine();
            Console.WriteLine("Press <ENTER> to terminate client.");
            Console.ReadLine();
        }
예제 #4
0
 public ComplexNumber Subtract(ComplexNumber n1, ComplexNumber n2)
 {
     return new ComplexNumber(n1.Real - n2.Real, n1.Imaginary - n2.Imaginary);
 }
예제 #5
0
 public ComplexNumber Add(ComplexNumber n1, ComplexNumber n2)
 {
     return new ComplexNumber(n1.Real + n2.Real, n1.Imaginary + n2.Imaginary);
 }
예제 #6
0
 public ComplexNumber Subtract(ComplexNumber n1, ComplexNumber n2)
 {
     return(new ComplexNumber(n1.Real - n2.Real, n1.Imaginary - n2.Imaginary));
 }
예제 #7
0
 public ComplexNumber Add(ComplexNumber n1, ComplexNumber n2)
 {
     return(new ComplexNumber(n1.Real + n2.Real, n1.Imaginary + n2.Imaginary));
 }