Exemple #1
0
 public Input()
 {
     add = new Addition();
     minus = new Subtraction();
     mult = new Multiply();
     div = new Division();
 }
Exemple #2
0
        public void run_calculation()
        {
            switch (inputList[1])
            {
            case "+":
                Addition addition = new Addition();
                addition.calculate(inputList);
                break;

            case "-":
                Subtraction subtraction = new Subtraction();
                subtraction.calculate(inputList);
                break;

            case "*":
                Multiplication multiplication = new Multiplication();
                multiplication.calculate(inputList);
                break;

            case "/":
                Division division = new Division();
                division.calculate(inputList);
                break;

            case "^":
                Exponentiation exponentiation = new Exponentiation();
                exponentiation.calculate(inputList);
                break;

            default:
                this.get_input();
                break;
            }
        }
        public IOperation GetOperation()
        {
            IOperation operation = null;

            switch (TypeOperation)
            {
            case "+":
                operation = new Sum();
                break;

            case "-":
                operation = new Subtraction();
                break;

            case "*":
                operation = new Multiplication();
                break;

            case "/":
                operation = new Division();
                break;

            default:
                Console.WriteLine("Operação não reconhecida!");
                Console.ReadKey();
                Environment.Exit(ERROR);
                break;
            }
            return(operation);
        }
 public CalculatorBody()
 {
     this.sum        = new Addition();
     this.difference = new Subtraction();
     this.product    = new Multiplication();
     this.quotient   = new Division();
     this.exponent   = new Exponentiation();
     this.sqrt       = new SquareRoot();
     this.input      = new UserInputOutput();
 }
 public CalculatorBody()
 {
     this.sum = new Addition();
     this.difference = new Subtraction();
     this.product = new Multiplication();
     this.quotient = new Division();
     this.exponent = new Exponentiation();
     this.sqrt = new SquareRoot();
     this.input = new UserInputOutput();
 }
Exemple #6
0
        private void addOperation()
        {
            Addition       addition       = new Addition();
            Subtraction    subtraction    = new Subtraction();
            Multiplication multiplication = new Multiplication();
            Division       division       = new Division();

            operations.Add(addition);
            operations.Add(subtraction);
            operations.Add(multiplication);
            operations.Add(division);
        }
Exemple #7
0
        public void Initialization()
        {
            arithmeticOperations.Add("+");
            arithmeticOperations.Add("/");
            arithmeticOperations.Add("-");
            arithmeticOperations.Add("*");

            Numeral1    one         = new Numeral1(this);
            Numeral2    two         = new Numeral2(this);
            Numeral3    three       = new Numeral3(this);
            Numeral4    four        = new Numeral4(this);
            Numeral5    five        = new Numeral5(this);
            Numeral6    six         = new Numeral6(this);
            Numeral7    seven       = new Numeral7(this);
            Numeral8    eight       = new Numeral8(this);
            Numeral9    nine        = new Numeral9(this);
            Numeral0    zero        = new Numeral0(this);
            Add         add         = new Add(this);
            Divide      divide      = new Divide(this);
            Multiply    multiply    = new Multiply(this);
            Subtraction Subtraction = new Subtraction(this);

            commands.Add(zero);
            commands.Add(one);
            commands.Add(two);
            commands.Add(three);
            commands.Add(four);
            commands.Add(five);
            commands.Add(six);
            commands.Add(seven);
            commands.Add(eight);
            commands.Add(nine);
            commands.Add(add);
            commands.Add(divide);
            commands.Add(multiply);
            commands.Add(Subtraction);
        }
Exemple #8
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;
        }
Exemple #9
0
        public static Operation createOperation(string item)
        {
            Operation temp = null;

            switch (item)
            {
            case "+":
                temp = new Addition();
                break;

            case "-":
                temp = new Subtraction();
                break;

            case "*":
                temp = new Multiplication();
                break;

            case "/":
                temp = new Division();
                break;
            }
            return(temp);
        }
Exemple #10
0
        // evaluator

        private void btnEq_Click(object sender, EventArgs e)
        {
            Expression expression;
            Double     sndArgument = new Double();


            if (textBoxRes.Text.Equals("x") || textBoxRes.Text.Equals("y") || textBoxRes.Text.Equals("z"))
            {
                using (var form = new CalculatorValueForVariables())
                {
                    var result = form.ShowDialog();
                    if (result == DialogResult.OK)
                    {
                        sndArgument = form.varValue;
                    }
                }
            }
            else
            {
                sndArgument = Double.Parse(textBoxRes.Text);
            }

            switch (calcOperator)
            {
            case "sqrt":
                if (!(resultValue < 0))
                {
                    expression      = new Sqrt(resultValue);
                    finalValue      = expression.Evaluate();
                    textBoxRes.Text = finalValue.ToString();
                }
                else
                {
                    textBoxRes.Text = "Can't calculate sqrt of a neg num!";
                }
                break;

            case "neg":
                expression      = new Opposite(resultValue);
                finalValue      = expression.Evaluate();
                textBoxRes.Text = finalValue.ToString();
                break;

            case "cos":
                expression      = new Cosinus(resultValue);
                finalValue      = expression.Evaluate();
                textBoxRes.Text = finalValue.ToString();
                break;

            case "sin":
                expression      = new Sinus(resultValue);
                finalValue      = expression.Evaluate();
                textBoxRes.Text = finalValue.ToString();
                break;

            case "exp":
                expression      = new Exponentation(resultValue);
                finalValue      = expression.Evaluate();
                textBoxRes.Text = finalValue.ToString();
                break;

            case "abs":
                expression      = new Abs(resultValue);
                finalValue      = expression.Evaluate();
                textBoxRes.Text = finalValue.ToString();
                break;

            case "log":
                if (resultValue > 0)
                {
                    expression      = new Log(resultValue);
                    finalValue      = expression.Evaluate();
                    textBoxRes.Text = finalValue.ToString();
                }
                else
                {
                    textBoxRes.Text = "Can't calculate log of a neg num!";
                }
                break;

            case "+":
                labelCurrentExpr.Text += sndArgument;
                expression             = new Addition(resultValue, sndArgument);
                finalValue             = expression.Evaluate();
                textBoxRes.Text        = finalValue.ToString();
                break;

            case "-":
                labelCurrentExpr.Text += sndArgument;
                expression             = new Subtraction(resultValue, sndArgument);
                finalValue             = expression.Evaluate();
                textBoxRes.Text        = finalValue.ToString();
                break;

            case "*":
                labelCurrentExpr.Text += sndArgument;
                expression             = new Multiplication(resultValue, sndArgument);
                finalValue             = expression.Evaluate();
                textBoxRes.Text        = finalValue.ToString();
                break;

            case "/":
                labelCurrentExpr.Text += sndArgument;
                if (!sndArgument.Equals(0))
                {
                    expression      = new Division(resultValue, sndArgument);
                    finalValue      = expression.Evaluate();
                    textBoxRes.Text = finalValue.ToString();
                }
                else
                {
                    textBoxRes.Text = "Can't divide by 0";
                }
                break;

            case "^":
                labelCurrentExpr.Text += sndArgument;
                expression             = new Power(resultValue, sndArgument);
                finalValue             = expression.Evaluate();
                textBoxRes.Text        = finalValue.ToString();
                break;

            case "%":
                labelCurrentExpr.Text += sndArgument;
                expression             = new Modulo(resultValue, sndArgument);
                finalValue             = expression.Evaluate();
                textBoxRes.Text        = finalValue.ToString();
                break;
            }
            resultValue           = 0;
            labelCurrentExpr.Text = "";
        }
Exemple #11
0
        public int Subtractions(int a, int b)
        {
            return(Subtraction.Sub(a, b));

            //return result;
        }