예제 #1
0
 //It transpose the calculated euqation at one side to the other.
 //For example: x+1 = 2 goes to x+1-2 = 0 and to x-1 = 0;
 private List <Operand> TransposeEquation(List <List <Operand> > finalOperands)
 {
     if (finalOperands.Count() > 1)
     {
         finalOperands[LEFT_OPERANDS_INDEX] = OperandCalculator.GetCalculatedOperands(
             finalOperands.ElementAt(LEFT_OPERANDS_INDEX),
             Operator.MINUS, finalOperands.ElementAt(RIGHT_OPERANDS_INDEX));
     }
     return(finalOperands.ElementAt(LEFT_OPERANDS_INDEX));
 }
예제 #2
0
 //It is the central method to cal all the neccessary methods to calculate
 //Terms and Operators provided through parameters.
 //The actual calculation of operands performed by OperandCalculator class.
 private List <Operand> PerformCalculation(List <Term> terms, List <char> operators)
 {
     while (terms.Count() > 1)
     {
         int  operatorIndex  = GetOperatorIndexToCalculate(operators);
         char operatorToCalc = operators.ElementAt(operatorIndex);
         Term leftTerm       = terms.ElementAt(operatorIndex);
         Term rightTerm      = terms.ElementAt((operatorIndex + 1));
         leftTerm.operands = OperandCalculator.GetCalculatedOperands(leftTerm.operands, operatorToCalc, rightTerm.operands);
         UpdateEquation(terms, operators, operatorIndex);
     }
     return(terms.ElementAt(0).operands);
 }
예제 #3
0
        //It calculates the euqation in the parenthesis provided.
        //In the case of (x+2)^n, it will multiply (x+2) n times.
        private List <Operand> GetCalculatedParenthesis(string parenthesis, int power, bool isNegative)
        {
            string         equationInParenthesis = OperandConverter.GetEquationInParenthesis(parenthesis);
            List <Operand> calculatedParenthesis = new TermCalculator().GetCalculatedEquation(equationInParenthesis);
            List <Operand> finalParenthesis      = calculatedParenthesis;

            for (int i = 1; i < power; i++)
            {
                finalParenthesis = OperandCalculator.GetCalculatedOperands(finalParenthesis, Operator.MULTIPLY, calculatedParenthesis);
            }
            if (isNegative)
            {
                finalParenthesis = OperandCalculator.GetCalculatedOperands(GetDefaultOperand(isNegative), Operator.MULTIPLY, finalParenthesis);
            }
            return(finalParenthesis);
        }
예제 #4
0
 //It checks if there is variable denominator such as (x^-1) and eliminates it by multiplying it with
 //its counter variable so that the equation can be easily calculated.
 private static List <Operand> EliminateVariableDenominator(List <Operand> function)
 {
     for (int i = 0; i < function.Count(); i++)
     {
         Operand currentOperand = function.ElementAt(i);
         if (currentOperand.Power < ZERO)
         {
             function = OperandCalculator.GetCalculatedOperands(function, Operator.MULTIPLY,
                                                                new List <Operand>()
             {
                 new Operand((currentOperand.Power * NEGATIVE_ONE), ONE)
             });
         }
     }
     return(function);
 }
예제 #5
0
        //It gets the number from Operand based on the power provided as parameter
        //and returns it to be further calculated in the calling method.
        private static int GetNumberFromOperandFor(List <Operand> function, int power)
        {
            int indexOfOperand = OperandCalculator.GetIndexOfSamePowerOperand(function, power);

            return((indexOfOperand == NEGATIVE_ONE) ? ZERO : function.ElementAt(indexOfOperand).NaturalNumber);
        }