Esempio n. 1
0
        //It is the central method to call all the neccessary functions to solve equation.
        //It returns calculated result as string to be displayed onto screen
        public string SolveEquation(string[] equation)
        {
            string stringEquation = String.Join(String.Empty, equation).ToString();

            ValidateThereIsVariableIn(stringEquation);
            string[]       separatedEquations = GetSeparatedEquationsBy(Operator.EQUAL, stringEquation);
            List <Operand> calculatedEquation = new TermCalculator().GetCalculatedEquation(separatedEquations);

            return(FunctionCalculator.GetResultFromFunction(calculatedEquation));
        }
Esempio n. 2
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);
        }