Example #1
0
        public void Simple()
        {
            var complexNumber1 = new ComplexNumber(-8, 4);
            var complexNumber2 = new ComplexNumber(3, 1);

            var divComplexNumber = complexNumber1.Divide(complexNumber2);

            Assert.AreEqual(-2, divComplexNumber.Real);
            Assert.AreEqual(2, divComplexNumber.Imaginary);

            divComplexNumber = complexNumber1.Divide(4);
            Assert.AreEqual(-2, divComplexNumber.Real);
            Assert.AreEqual(1, divComplexNumber.Imaginary);

            complexNumber1 = new ComplexNumber(2, 6);
            complexNumber2 = new ComplexNumber(4, 1);

            divComplexNumber = complexNumber1.Divide(complexNumber2);

            Assert.AreEqual(14 / (double) 17, divComplexNumber.Real);
            Assert.AreEqual(22 / (double) 17, divComplexNumber.Imaginary);
        }
Example #2
0
        public void Simple()
        {
            var complexNumber1 = new ComplexNumber(-8, 4);
            var complexNumber2 = new ComplexNumber(3, 1);

            var divComplexNumber = complexNumber1.Divide(complexNumber2);

            Assert.AreEqual(-2, divComplexNumber.Real);
            Assert.AreEqual(2, divComplexNumber.Imaginary);

            divComplexNumber = complexNumber1.Divide(4);
            Assert.AreEqual(-2, divComplexNumber.Real);
            Assert.AreEqual(1, divComplexNumber.Imaginary);

            complexNumber1 = new ComplexNumber(2, 6);
            complexNumber2 = new ComplexNumber(4, 1);

            divComplexNumber = complexNumber1.Divide(complexNumber2);

            Assert.AreEqual(14 / (double)17, divComplexNumber.Real);
            Assert.AreEqual(22 / (double)17, divComplexNumber.Imaginary);
        }
Example #3
0
        public void DivideDoubleExample()
        {
            var complexNumber1 = new ComplexNumber(8, 4);

            var div = complexNumber1.Divide(2);

            Assert.AreEqual(div.Real, 4);
            Assert.AreEqual(div.Imaginary, 2);
        }
Example #4
0
        public void DivideComplexNumberExample()
        {
            var complexNumber1 = new ComplexNumber(-8, 4);
            var complexNumber2 = new ComplexNumber(3, 1);

            var div = complexNumber1.Divide(complexNumber2);

            Assert.AreEqual(div.Real, -2);
            Assert.AreEqual(div.Imaginary, 2);
        }
        static void Main(string[] args)
        {
            Console.WriteLine("=== Complex Numbers ===");

            Console.Write("Primo Numero - Parte Reale: ");
            var realOneString = Console.ReadLine();

            double.TryParse(realOneString, out double realOne);

            Console.Write("Primo Numero - Parte Immaginaria: ");
            var immagOneString = Console.ReadLine();

            double.TryParse(immagOneString, out double immagOne);

            Console.Write("Secondo Numero - Parte Reale: ");
            var realTwoString = Console.ReadLine();

            double.TryParse(realTwoString, out double realTwo);

            Console.Write("Secondo Numero - Parte Immaginaria: ");
            var immagTwoString = Console.ReadLine();

            double.TryParse(immagTwoString, out double immagTwo);

            Console.Write("Operazione (+, -, *, /): ");
            var op = Console.ReadLine();

            var           cnOne = new ComplexNumber(realOne, immagOne);
            var           cnTwo = new ComplexNumber(realTwo, immagTwo);
            ComplexNumber result;

            switch (op)
            {
            case "+":
                result = cnOne.Add(cnTwo);
                Console.WriteLine($"ADD: ({result.Real}, {result.Immag})");
                break;

            case "-":
                result = cnOne.Subtract(cnTwo);
                Console.WriteLine($"SUBTRACT: ({result.Real}, {result.Immag})");
                break;

            case "*":
                result = cnOne.Multiply(cnTwo);
                Console.WriteLine($"MULTIPLY: ({result.Real}, {result.Immag})");
                break;

            case "/":
                result = cnOne.Divide(cnTwo);
                Console.WriteLine($"DIVIDE: ({result.Real}, {result.Immag})");
                break;

            default:
                Console.WriteLine("Operazione invalida");
                break;
            }

            Console.WriteLine($"Modulo di ({cnOne.Real}, {cnOne.Immag}): {cnOne.Modulo}");
            Console.WriteLine($"Coniugato di ({cnTwo.Real}, {cnTwo.Immag}): ({cnTwo.Coniugato.Real}, {cnTwo.Coniugato.Immag})");
        }