/// <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')));
            }
        }
Beispiel #2
0
        /// <summary>
        /// Adds the two operands together
        /// </summary>
        /// <param name="one">operand one</param>
        /// <param name="two">operand two</param>
        /// <returns></returns>
        public string Add(ComplexData one, ComplexData two)
        {
            realNumberResult = one.getRealNumber() + two.getRealNumber();
            imagNumberResult = one.getComplexNumber() + two.getComplexNumber();

            result = realNumberResult + "" + imagNumberResult.ToString("+0.###;-#.###") + "i";
            return(result);
        }
Beispiel #3
0
        /// <summary>
        /// Multiplies
        /// </summary>
        /// <param name="one">operand one</param>
        /// <param name="two">operand two</param>
        /// <returns></returns>
        public string Multiply(ComplexData one, ComplexData two)
        {
            realNumberResult = (one.getRealNumber() * two.getRealNumber()) + ((two.getComplexNumber() * one.getComplexNumber()) * -1);
            imagNumberResult = (one.getComplexNumber() * two.getRealNumber()) + (two.getComplexNumber() * one.getRealNumber());

            result = realNumberResult + "" + imagNumberResult.ToString("+0.###;-#.###") + "i";

            return(result);
        }
Beispiel #4
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);
        }