예제 #1
0
        /// <summary>
        /// 数字を一つプッシュします。
        /// </summary>
        /// <param name="num">一桁の数字(一桁でない場合はArgumentOutOfRangeExceptionをスロー)</param>
        public void PushNumber(int num)
        {
            if (num < 0 || 9 < num)
            {
                throw new ArgumentOutOfRangeException();
            }

            try {
                if (Operator == Operators.None)
                {
                    Answer.PushNumber(num);
                }
                else if (OpsValue != null)
                {
                    OpsValue.PushNumber(num);
                }
                else
                {
                    OpsValue = new CalculatorNumber();
                    OpsValue.PushNumber(num);
                }
            }catch {
                PushAllClear();
            }
        }
예제 #2
0
        /// <summary>
        /// 演算子に基づいて計算を実行します。
        /// </summary>
        protected void CalAnswer()
        {
            try {
                switch (Operator)
                {
                case Operators.None:
                case Operators.Equal:
                    break;

                case Operators.Plus:
                    Answer = new CalculatorNumber(Answer.Value + (OpsValue ?? Answer).Value);
                    break;

                case Operators.Minus:
                    Answer = new CalculatorNumber(Answer.Value - (OpsValue ?? Answer).Value);
                    break;

                case Operators.Multi:
                    Answer = new CalculatorNumber(Answer.Value * (OpsValue ?? Answer).Value);
                    break;

                case Operators.Divide:
                    Answer = new CalculatorNumber(Answer.Value / (OpsValue ?? Answer).Value);
                    break;
                }

                OpsValue = null;
                Operator = Operators.None;
            }catch (OverflowException) {
                PushAllClear();
            }
        }
예제 #3
0
        /// <summary>
        /// クリア(C)をプッシュします。
        /// </summary>
        public void PushClear()
        {
            switch (Operator)
            {
            case Operators.None:
            case Operators.Equal:
                PushAllClear();
                break;

            default:
                OpsValue = new CalculatorNumber(0);
                break;
            }
        }
예제 #4
0
        /// <summary>
        /// Answer, OpsValue, Operatorの3つの値で初期化(3つとも省略可能)
        /// </summary>
        /// <param name="_ans">現在の答え</param>
        /// <param name="_opsValue">演算対象を入力中の一時保管場所</param>
        /// <param name="_operator">現在演算させようとしている処理の種類</param>
        public NormalCalculator(decimal _ans = 0, decimal?_opsValue = null, Operators _operator = Operators.None)
        {
            Answer = new CalculatorNumber(_ans);

            if (_opsValue == null)
            {
                OpsValue = null;
            }
            else
            {
                OpsValue = new CalculatorNumber(_opsValue ?? 0);
            }

            Operator = _operator;
        }
예제 #5
0
 /// <summary>
 /// ピリオドをプッシュします。
 /// </summary>
 public void PushPeriod()
 {
     if (Operator == Operators.None)
     {
         Answer.PushPeriod();
     }
     else if (OpsValue != null)
     {
         OpsValue.PushPeriod();
     }
     else
     {
         OpsValue = new CalculatorNumber();
         OpsValue.PushPeriod();
     }
 }
예제 #6
0
 public NormalCalculator(NormalCalculator ops)
 {
     Answer   = new CalculatorNumber(ops.Answer);
     OpsValue = new CalculatorNumber(ops.OpsValue);
     Operator = ops.Operator;
 }
예제 #7
0
 /// <summary>
 /// オールクリア(AC)をプッシュします。
 /// </summary>
 public void PushAllClear()
 {
     Answer.Clear();
     OpsValue = null;
     Operator = Operators.None;
 }
예제 #8
0
 public CalculatorNumber(CalculatorNumber ops)
 {
     ValString = ops.ValString;
 }