コード例 #1
0
        public override double Calculate()
        {
            var rightOperandResult = RightOperand.Calculate();

            if (rightOperandResult.Equals(0))
            {
                throw new DivideByZeroException();
            }

            return(LeftOperand.Calculate() / RightOperand.Calculate());
        }
コード例 #2
0
        public override double Calculate()
        {
            double leftValue  = LeftOperand.Calculate();
            double rightValue = RightOperand.Calculate();

            switch (Operation)
            {
            case "*": value = leftValue * rightValue; break;

            case "+": value = leftValue + rightValue; break;

            case "^": value = Math.Pow(leftValue, rightValue); break;

            case "/": value = leftValue / rightValue; break;

            case "-": value = leftValue - rightValue; break;

            default: throw new Exception("Неизвестный бинарный оператор " + Operation);
            }
            return(value);
        }
コード例 #3
0
 public override double Calculate()
 {
     return(Math.Pow(LeftOperand.Calculate(), RightOperand.Calculate()));
 }
コード例 #4
0
ファイル: Addition.cs プロジェクト: Mikhailo98/mnprogram
 public override double Calculate()
 {
     return(LeftOperand.Calculate() + RightOperand.Calculate());
 }