コード例 #1
0
        //It converts string expression into Operand object
        //It calculates power associated with the number like 2^2 will be converted into 4.
        private void ConvertToNaturalNumber(string operandToConvert)
        {
            bool isNegative = operandToConvert.ElementAt(0).Equals(Operator.MINUS);
            int  numberPart = OperandConverter.GetNumberPartFromNaturalNumber(operandToConvert, (isNegative) ? 1 : 0);
            int  powerPart  = OperandConverter.GetPowerFrom(operandToConvert);

            this.NaturalNumber = OperandConverter.GetPoweredNumber(numberPart, powerPart, isNegative);
        }
コード例 #2
0
ファイル: Term.cs プロジェクト: c0go233/EquationCalculator
        //It converts parenthesis into Term object that will holding a number of Operands.
        //In the case of (x+1)^0, it will treat it as "1".
        private void ConvertFromParenthesis(string parenthesis)
        {
            int  power      = OperandConverter.GetPowerFromParenthesis(parenthesis);
            bool isNegative = parenthesis.ElementAt(0) == Operator.MINUS;

            if (power == 0)
            {
                this.operands = GetDefaultOperand(isNegative);
            }
            else
            {
                this.operands = GetCalculatedParenthesis(parenthesis, power, isNegative);
            }
        }
コード例 #3
0
ファイル: Term.cs プロジェクト: c0go233/EquationCalculator
        //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 converts string expression into Operand object of variable.
 //In the case of 2x^0, it will be treated as 1.
 private void ConvertToVariable(string operandToConvert)
 {
     this.NaturalNumber = OperandConverter.GetNaturalNumberFromVariable(operandToConvert);
     this.Power         = OperandConverter.GetPowerFrom(operandToConvert);
 }