Пример #1
0
        public void PerformOperation(OperationType operation)
        {
            //int operation;
            IOperation operationType = null;

            switch (operation)
            {
            case OperationType.Add:
            {
                operationType = new AddOperation();
                break;
            }

            case OperationType.Minus:
            {
                operationType = new MinusOperation();
                break;
            }

            case OperationType.Multiply:
            {
                operationType = new MultiplyOperation();
                break;
            }

            case OperationType.Divide:
            {
                operationType = new DivideOperation();
                break;
            }

            case OperationType.Negate:
            {
                operationType = new NegateOperation();
                break;
            }
            }
            if (operationType != null)
            {
                operationType.Perform(numbers);
            }
        }
Пример #2
0
        public string PerformOperation(OperationType operationType)
        {
            IOperation operation = null;

            switch (operationType)
            {
            case OperationType.ADD:
                operation = new AddOperation();
                break;

            case OperationType.MINUS:
                operation = new SubtractOperation();
                break;

            case OperationType.MULTIPLY:
                operation = new MultiplyOperation();
                break;

            case OperationType.DIVIDE:
                operation = new DivideOperation();
                break;

            case OperationType.NEGATE:
                operation = new NegateOperation();
                break;

            case OperationType.SQROOT:
                operation = new SquareRootOperation();
                break;

            case OperationType.EXPONENT:
                operation = new ExponentOperation();
                break;

            case OperationType.NATURAL:
                operation = new NaturalOperation();
                break;

            case OperationType.RECIPROCAL:
                operation = new ReciprocalOperation();
                break;

            case OperationType.SIN:
                operation = new SinOperation();
                break;

            case OperationType.COS:
                operation = new CosOperation();
                break;
            }
            if (operation != null)
            {
                try
                {
                    operation.Perform(CalcStack);
                }
                catch (Exception e)
                {
                    return(e.ToString());
                }
            }
            return(string.Empty);
        }