Exemplo n.º 1
0
        /// <summary>
        /// Splits the operand into 2 data types: real number and complex number.
        /// </summary>
        /// <param name="operand">This is the original operand from textbox. It uses this operand
        /// to split it and put real and complex numbers into the class object. </param>
        /// <param name="OperandObject"> puts in operand object so you can get the real number and
        /// imaginary numbers</param>
        public void OperandSplitter(string operand, ComplexData OperandObject)
        {
            string newTxtOperand = operand;
            string sign          = "";

            if (operand.StartsWith("-"))
            {
                newTxtOperand = operand.Substring(1);
                sign          = "-";
            }

            if (newTxtOperand.Contains("+"))
            {
                string[] operandOneArray = newTxtOperand.Split('+');
                operandOneArray[0] = operandOneArray[0].Insert(0, sign);
                OperandObject.setRealNumber(Double.Parse(operandOneArray[0]));
                OperandObject.setComplexNumber(Double.Parse(operandOneArray[1].TrimEnd('i')));
            }
            else if (newTxtOperand.Contains("-"))
            {
                string[] operandOneArray = newTxtOperand.Split('-');
                operandOneArray[0] = operandOneArray[0].Insert(0, sign);
                operandOneArray[1] = operandOneArray[1].Insert(0, "-");
                OperandObject.setRealNumber(Double.Parse(operandOneArray[0]));
                operandOneArray[1].TrimEnd('i');
                OperandObject.setComplexNumber(Double.Parse(operandOneArray[1].TrimEnd('i')));
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Divides
        /// </summary>
        /// <param name="one">operand one</param>
        /// <param name="two">operand two</param>
        /// <returns></returns>
        public string Divide(ComplexData one, ComplexData two)
        {
            ComplexData conjugate   = new ComplexData();
            string      numerator   = "";
            string      denominator = "";

            conjugate.setComplexNumber(two.getComplexNumber() * -1);
            conjugate.setRealNumber(two.getRealNumber());
            numerator   = Multiply(one, conjugate);
            denominator = Multiply(two, conjugate);

            result = numerator + "\n" + "-----------\n" + denominator;
            return(result);
        }