예제 #1
0
 public BasicCalculator()
 {
     _addition    = new Addition();
     _subtraction = new Subtraction();
     _multiply    = new Multiply();
     _division    = new Division();
 }
예제 #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);
        }
예제 #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;
 }
예제 #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);
        }
예제 #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);
        }
예제 #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));
        }
예제 #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());
        }
예제 #8
0
 public MathProblemPuzzleEntry(IMathOperation mathOperation)
 {
     this.MathOperation = mathOperation;
 }
예제 #9
0
 public BasicCalculator(IMathOperation _mathOperation)
 {
     this._mathOperation = _mathOperation;
 }
 public void SetNextOperation(IMathOperation nextOperation)
 {
     this.NextOperation = nextOperation;
 }
예제 #11
0
 public static void MyExtendedMethod(this IMathOperation obj)
 {
     Console.WriteLine("MyExtendedMethod: " + obj.Add(10, 30));
 }
예제 #12
0
 public MathOperation(MathOperationResult leftOp, MathOperationResult rightOp, IMathOperation mathOp) : base(0)
 {
     LeftOperand  = leftOp.Result;
     RightOperand = rightOp.Result;
     Operation    = mathOp;
 }
예제 #13
0
 public TriangleViewModel(IServerCommunication communication, IMathOperation mathOperation)
 {
     _communication = communication;
     _mathOperation = mathOperation;
 }
예제 #14
0
 public DipInd(IMathOperation pobj)
 {
     obj = pobj;
 }
예제 #15
0
 public MathController(IMathOperation mathOperation)
 {
     _mathOperation = mathOperation;
 }
예제 #16
0
 public MathOperationTest(IMathOperation mathOperation)
 {
     _mathOperation = mathOperation;
 }
 public ExpressionManager()
 {
     this.operands      = new Queue <long>();
     this.operators     = new Queue <OperatorType>();
     this.mathOperation = this.RegisterMathOperations();
 }
예제 #18
0
 public Expression(IMathOperation mathOperation)
 {
     this.MathOperation = mathOperation;
 }