Esempio n. 1
0
 public Input()
 {
     add = new Addition();
     minus = new Subtraction();
     mult = new Multiply();
     div = new Division();
 }
Esempio n. 2
0
        public decimal Calculate(string calculate, decimal num1, decimal num2)
        {
            //int first = Convert.ToInt32(num1);
            //int second = Convert.ToInt32(num2);

            switch (calculate)
            {
                case "1":
                    Addition addition = new Addition();
                    answer = addition.AddThese(num1, num2);
                    Console.WriteLine("Your answer is: " + answer);
                    break;
                case "2":
                    Subtraction subtraction = new Subtraction();
                    answer = subtraction.SubtractThese(num1, num2);
                    Console.WriteLine("Your answer is: " + answer);
                    break;
                case "3":
                    Multiply multiply = new Multiply();
                    answer = multiply.MultiplyThese(num1, num2);
                    Console.WriteLine("Your answer is: " + answer);
                    break;
                case "4":
                    Divide divide = new Divide();
                    answer = divide.DivideThese(num1, num2);
                    Console.WriteLine("Your answer is: " + answer);
                    break;
                case "5":
                    Exponential exponential = new Exponential();
                    exponential.ExponentThese(num1, num2);
                    break;
                default:
                    Console.WriteLine("Not a valid choice!");
                    break;
            }
            return answer;
        }
Esempio n. 3
0
        //THE MOTHER FUNCTION
        public int handledIt(string input)
        {
            //declare variable to hold result from operation
            int result = 0;

            //set stack_record so that I can access the last user input
            stack_record.lastQ = input;

            //create new expression class to handle parsing user input
            Expression myExp = new Expression();

            //allow the container to be set from the parseExpression method
            Container answer = myExp.ParseExpression(input);

            //search the equation for a constant and parse it out to do the math on.
            string ContString = "abcdefghijklmnopqrstuvwxyz";

            foreach (var letter in input)
            {
                if (ContString.IndexOf(letter) == 0)
                {
                    Console.WriteLine("No Constant Defined");
                }
                else
                {
                }
            }


            //shorthand the variables from Container class
            int    lhs      = answer.LHS;
            int    rhs      = answer.RHS;
            char   op       = answer.OP;
            string constant = answer.CONS;

            //run the operator logic
            if (op == '+')
            {
                Add add_me = new Add();
                result = add_me.addIt(lhs, rhs);
            }
            else if (op == '-')
            {
                Subtract subtract_me = new Subtract();
                result = subtract_me.subtractIt(lhs, rhs);
            }
            else if (op == '*')
            {
                Multiply multiply_me = new Multiply();
                result = multiply_me.multiplyIt(lhs, rhs);
            }
            else if (op == '/')
            {
                Divide divide_me = new Divide();
                result = divide_me.divideIt(lhs, rhs);
            }
            else if (op == '%')
            {
                Modulo modulo_me = new Modulo();
                result = modulo_me.moduloIt(lhs, rhs);
            }
            else if (op == '=')
            {
                conts.Add(constant, rhs);
                result = rhs;
            }
            else
            {
                throw new InvalidOperationException("no valid operator found");
            }

            //set stack_record result for later access
            stack_record.last = result;
            return(result);
        }
Esempio n. 4
0
 void CreateOperators()
 {
     // Only one of each operation Token needs to be created
     opAdd = new Add(workStack);
     opSubtract = new Subtract(workStack);
     opMultiply = new Multiply(workStack);
     opDivide = new Divide(workStack);
     opPower = new Power(workStack);
     opBracket = new Bracket();
     opUnaryMinus = new UnaryMinus(workStack);
     opUnaryPlus = new UnaryPlus();
     opSqrt = new Sqrt(workStack);
     opSin = new Sin(workStack);
     opCos = new Cos(workStack);
     opTan = new Tan(workStack);
     opLog = new Log(workStack);
     opAsin = new Asin(workStack);
     opAcos = new Acos(workStack);
     opAtan = new Atan(workStack);
     functions = new Dictionary<string, Function>
     {
         {"sqr", opSqrt },
         {"sin", opSin },
         {"cos", opCos },
         {"tan", opTan },
         {"log", opLog },
         {"asin", opAsin },
         {"acos", opAcos },
         {"atan", opAtan }
     };
     binaryOperators = new Dictionary<char, BinaryOperator>
     {
         {'+', opAdd },
         {'-', opSubtract },
         {'*', opMultiply },
         {'/', opDivide },
         {'^',opPower }
     };
 }