Exemplo n.º 1
0
 public BasicCalculator()
 {
     _addition    = new Addition();
     _subtraction = new Subtraction();
     _multiply    = new Multiply();
     _division    = new Division();
 }
Exemplo n.º 2
0
        /// <summary>
        /// Найти результат одной операции
        /// </summary>
        /// <param name="expression"> Полное выражение с этой операцией </param>
        /// <param name="operation"> Операция </param>
        private void SolveOperation(IList <object> expression, IMathOperation operation)
        {
            var opIndx  = expression.IndexOf(operation);
            var leftOp  = expression[opIndx - 1] as MathOperationResult;
            var rightOp = expression[opIndx + 1] as MathOperationResult;

            if (operation == null)
            {
                throw new SolveExpressionException("Опереация не определена!");
            }
            if (leftOp == null)
            {
                throw new SolveExpressionException($"Левый опереанд {expression[opIndx - 1]} не определен!");
            }
            if (rightOp == null)
            {
                throw new SolveExpressionException($"Правый опереанд {expression[opIndx + 1]} не определен!");
            }

            MathOperationResult newMathOperation = new MathOperation(leftOp, rightOp, operation);

            expression[opIndx - 1] = newMathOperation;
            expression.Remove(operation);
            expression.Remove(rightOp);
        }
Exemplo n.º 3
0
 public Task(int operand1, int operand2, IMathOperation mathOperation, Task previousTask)
 {
     Operand1      = operand1;
     Operand2      = operand2;
     MathOperation = mathOperation;
     CorrectAnswer = MathOperation.GetResult(Operand1, Operand2);
     PreviousTask  = previousTask;
 }
Exemplo n.º 4
0
        public double GetCalculationResult(List <double> dataForProceed)
        {
            summ = PopFirstOperand(dataForProceed);

            for (int i = 0; i < dataForProceed.Count(); i++)
            {
                IMathOperation operation = mathDictionary[rand.Next(1, 4)];
                summ = operation.GetResult(summ, dataForProceed[i]);
            }
            return(summ);
        }
Exemplo n.º 5
0
        public void Test(IMathOperation mathExercise)
        {
            var leftOperand  = numberReader.ReadNumber($"Zadejte 1. číslo pro {mathExercise.OperationName}: ");
            var rightOperand = numberReader.ReadNumber($"Zadejte 2. číslo pro {mathExercise.OperationName}: ");

            var askForSolution = $"{leftOperand} {mathExercise.Operand} {rightOperand} = ";
            var userAnswer     = numberReader.ReadNumber(askForSolution);

            var correctResult = mathExercise.GetCorrectResult(leftOperand, rightOperand);

            WriteResultMessage(correctResult, userAnswer);
        }
Exemplo n.º 6
0
        public double CalculateAverage(IEnumerable <double> values, IMathOperation <IEnumerable <double>, double> averagingMethod)
        {
            if (values == null)
            {
                throw new ArgumentNullException($"The {nameof(values)} can not be null.");
            }

            if (averagingMethod == null)
            {
                throw new ArgumentNullException($"The {nameof(averagingMethod)} can not be null.");
            }

            return(CalculateAverage(values, averagingMethod.MakeMathOperation));
        }
Exemplo n.º 7
0
        public string GetCalculationFullExpresion(List <double> dataForProceed)
        {
            StringBuilder fullExpression = new StringBuilder();

            summ = PopFirstOperand(dataForProceed);
            fullExpression.Append(summ);

            for (int i = 0; i < dataForProceed.Count(); i++)
            {
                IMathOperation operation = mathDictionary[rand.Next(1, 4)];
                summ = operation.GetResult(summ, dataForProceed[i]);

                fullExpression.Append(operation.GetSign());
                fullExpression.Append(dataForProceed[i]);
            }
            return(fullExpression.Append("=" + summ).ToString());
        }
Exemplo n.º 8
0
 public MathProblemPuzzleEntry(IMathOperation mathOperation)
 {
     this.MathOperation = mathOperation;
 }
Exemplo n.º 9
0
 public BasicCalculator(IMathOperation _mathOperation)
 {
     this._mathOperation = _mathOperation;
 }
Exemplo n.º 10
0
 public void SetNextOperation(IMathOperation nextOperation)
 {
     this.NextOperation = nextOperation;
 }
Exemplo n.º 11
0
 public static void MyExtendedMethod(this IMathOperation obj)
 {
     Console.WriteLine("MyExtendedMethod: " + obj.Add(10, 30));
 }
Exemplo n.º 12
0
 public MathOperation(MathOperationResult leftOp, MathOperationResult rightOp, IMathOperation mathOp) : base(0)
 {
     LeftOperand  = leftOp.Result;
     RightOperand = rightOp.Result;
     Operation    = mathOp;
 }
Exemplo n.º 13
0
 public TriangleViewModel(IServerCommunication communication, IMathOperation mathOperation)
 {
     _communication = communication;
     _mathOperation = mathOperation;
 }
Exemplo n.º 14
0
 public DipInd(IMathOperation pobj)
 {
     obj = pobj;
 }
Exemplo n.º 15
0
 public MathController(IMathOperation mathOperation)
 {
     _mathOperation = mathOperation;
 }
Exemplo n.º 16
0
 public MathOperationTest(IMathOperation mathOperation)
 {
     _mathOperation = mathOperation;
 }
 public ExpressionManager()
 {
     this.operands      = new Queue <long>();
     this.operators     = new Queue <OperatorType>();
     this.mathOperation = this.RegisterMathOperations();
 }
Exemplo n.º 18
0
 public Expression(IMathOperation mathOperation)
 {
     this.MathOperation = mathOperation;
 }