public BasicCalculator() { _addition = new Addition(); _subtraction = new Subtraction(); _multiply = new Multiply(); _division = new Division(); }
/// <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); }
public Task(int operand1, int operand2, IMathOperation mathOperation, Task previousTask) { Operand1 = operand1; Operand2 = operand2; MathOperation = mathOperation; CorrectAnswer = MathOperation.GetResult(Operand1, Operand2); PreviousTask = previousTask; }
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); }
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); }
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)); }
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()); }
public MathProblemPuzzleEntry(IMathOperation mathOperation) { this.MathOperation = mathOperation; }
public BasicCalculator(IMathOperation _mathOperation) { this._mathOperation = _mathOperation; }
public void SetNextOperation(IMathOperation nextOperation) { this.NextOperation = nextOperation; }
public static void MyExtendedMethod(this IMathOperation obj) { Console.WriteLine("MyExtendedMethod: " + obj.Add(10, 30)); }
public MathOperation(MathOperationResult leftOp, MathOperationResult rightOp, IMathOperation mathOp) : base(0) { LeftOperand = leftOp.Result; RightOperand = rightOp.Result; Operation = mathOp; }
public TriangleViewModel(IServerCommunication communication, IMathOperation mathOperation) { _communication = communication; _mathOperation = mathOperation; }
public DipInd(IMathOperation pobj) { obj = pobj; }
public MathController(IMathOperation mathOperation) { _mathOperation = mathOperation; }
public MathOperationTest(IMathOperation mathOperation) { _mathOperation = mathOperation; }
public ExpressionManager() { this.operands = new Queue <long>(); this.operators = new Queue <OperatorType>(); this.mathOperation = this.RegisterMathOperations(); }
public Expression(IMathOperation mathOperation) { this.MathOperation = mathOperation; }