예제 #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
파일: client.cs 프로젝트: ssickles/archive
        static void Main()
        {
            // Create a client 
            XmlSerializerCalculatorClient client = new XmlSerializerCalculatorClient();

            // 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
파일: service.cs 프로젝트: ssickles/archive
 public ComplexNumber Subtract(ComplexNumber n1, ComplexNumber n2)
 {
     //Return the derived type
     return new ComplexNumberWithMagnitude(n1.Real - n2.Real, n1.Imaginary - n2.Imaginary);
 }
예제 #5
0
파일: service.cs 프로젝트: ssickles/archive
 public ComplexNumber Add(ComplexNumber n1, ComplexNumber n2)
 {
     //Return the derived type
     return new ComplexNumberWithMagnitude(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);
 }
예제 #8
0
 public ComplexNumber Subtract(ComplexNumber n1, ComplexNumber n2)
 {
     return new ComplexNumber(n1.Real - n2.Real, n1.Imaginary - n2.Imaginary);
 }
예제 #9
0
 public ComplexNumber Add(ComplexNumber n1, ComplexNumber n2)
 {
     return new ComplexNumber(n1.Real + n2.Real, n1.Imaginary + n2.Imaginary);
 }
예제 #10
0
파일: client.cs 프로젝트: ssickles/archive
        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);
            if (result is ComplexNumberWithMagnitude)
            {
                Console.WriteLine("Magnitude: {0}", ((ComplexNumberWithMagnitude)result).Magnitude);
            }
            else
            {
                Console.WriteLine("No magnitude was sent from the service");
            }


            // 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);
            if (result is ComplexNumberWithMagnitude)
            {
                Console.WriteLine("Magnitude: {0}", ((ComplexNumberWithMagnitude)result).Magnitude);
            }
            else
            {
                Console.WriteLine("No magnitude was sent from the service");
            }

            // 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);
            if (result is ComplexNumberWithMagnitude)
            {
                Console.WriteLine("Magnitude: {0}", ((ComplexNumberWithMagnitude)result).Magnitude);
            }
            else
            {
                Console.WriteLine("No magnitude was sent from the service");
            }

            // 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);
            if (result is ComplexNumberWithMagnitude)
            {
                Console.WriteLine("Magnitude: {0}", ((ComplexNumberWithMagnitude)result).Magnitude);
            }
            else
            {
                Console.WriteLine("No magnitude was sent from the service");
            }

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

            Console.WriteLine();
            Console.WriteLine("Press <ENTER> to terminate client.");
            Console.ReadLine();
        }
예제 #11
0
 public ComplexNumber Subtract(ComplexNumber n1, ComplexNumber n2)
 {
     //Return the derived type
     return(new ComplexNumberWithMagnitude(n1.Real - n2.Real, n1.Imaginary - n2.Imaginary));
 }
예제 #12
0
 public ComplexNumber Add(ComplexNumber n1, ComplexNumber n2)
 {
     //Return the derived type
     return(new ComplexNumberWithMagnitude(n1.Real + n2.Real, n1.Imaginary + n2.Imaginary));
 }
예제 #13
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);
            if (result is ComplexNumberWithMagnitude)
            {
                Console.WriteLine("Magnitude: {0}", ((ComplexNumberWithMagnitude)result).Magnitude);
            }
            else
            {
                Console.WriteLine("No magnitude was sent from the service");
            }


            // 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);
            if (result is ComplexNumberWithMagnitude)
            {
                Console.WriteLine("Magnitude: {0}", ((ComplexNumberWithMagnitude)result).Magnitude);
            }
            else
            {
                Console.WriteLine("No magnitude was sent from the service");
            }

            // 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);
            if (result is ComplexNumberWithMagnitude)
            {
                Console.WriteLine("Magnitude: {0}", ((ComplexNumberWithMagnitude)result).Magnitude);
            }
            else
            {
                Console.WriteLine("No magnitude was sent from the service");
            }

            // 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);
            if (result is ComplexNumberWithMagnitude)
            {
                Console.WriteLine("Magnitude: {0}", ((ComplexNumberWithMagnitude)result).Magnitude);
            }
            else
            {
                Console.WriteLine("No magnitude was sent from the service");
            }

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

            Console.WriteLine();
            Console.WriteLine("Press <ENTER> to terminate client.");
            Console.ReadLine();
        }