コード例 #1
0
        //button √
        private void BtnSquareRoot_Click(object sender, RoutedEventArgs e)
        {
            if (NoCalculationsYet == true)
            {
                //Converting the Current number which is inside the TbInputNumbers TextBlock
                //Adding the Current number to the Memory array,Incrementing the MemoryIndex by one
                //Storing the calculation in the result variable (Rounding the result)
                //Showing the user the given result in the TbResultmemory textBlock
                //We add the button's text to the TbCalculationProgress textblock
                //Adding the result to the Memory array and ResultMemory array
                //incrementing the Memory array's and ResultMemory array's index counter by one
                //Incrementing the navigator by one and setting the navigator on this side to the new value

                double CurrentNumber = Convert.ToDouble(TbInputNumbers.Text);
                Calculations.AddToMemory(CurrentNumber);
                Calculations.IncrementMemoryIndexByOne();

                double Result = Calculations.SquareRootNumber();
                Math.Round(Result, 10);

                TbResultMemory.Text        = Result.ToString();
                TbCalculationProgress.Text = "√" + CurrentNumber + "";

                Calculations.AddToMemory(Result);

                Calculations.AddToResultMemory(Result);
                Calculations.IncrementResultMemoryIndexByOne();

                Calculations.IncrementResultMemoryNavigatorByOne();


                //Setting the NoCalculationsYet variable to false as we've just calculated the result
                NoCalculationsYet = false;
            }
            else if (NoCalculationsYet == false)
            {
                //Storing the previous element of the Memory array in the Previous number variable
                //Storing the calculation in the result variable (Rounding the result)
                //Showing the user the given result in the TbResultmemory textBlock
                //We add the button's text to the TbCalculationProgress textblock
                //Adding the result to the Memory array and ResultMemory array
                //incrementing the Memory array's and ResultMemory array's index counter by one
                //Incrementing the navigator by one and setting the navigator on this side to the new value

                Calculations.IncrementMemoryIndexByOne();
                double PreviousNumber = Calculations.GiveBackPreviousElementOfMemory();
                double Result         = Calculations.SquareRootNumber();
                Math.Round(Result, 10);

                TbResultMemory.Text        = Result.ToString();
                TbCalculationProgress.Text = "(" + PreviousNumber + " * " + PreviousNumber + ")";

                Calculations.AddToMemory(Result);

                Calculations.AddToResultMemory(Result);
                Calculations.IncrementResultMemoryIndexByOne();

                Calculations.IncrementResultMemoryNavigatorByOne();
            }

            //Setting the UserCanDeleteLastNumber variable to false as the user cannot Delete back from the result
            UserCanDeleteLastNumber = false;

            //Setting this variable to false as the user can use division or multiplication, because the Memory array is not empty
            NewCalculation = false;

            //After the calculation this variable will always be one
            CalculationIsOnGoing = 1;

            //Setting the TbInputNumbers Textblock's text to default after every calculation
            TbInputNumbers.Text = "0";
        }
コード例 #2
0
        //Button =
        private void BtnSummarize_Click(object sender, RoutedEventArgs e)
        {
            //We add the button's text to the TbCalculationProgress textblock
            TbCalculationProgress.Text += "=";


            //The most recently used operator is required for the right calculation method
            string CalculationProgress = TbCalculationProgress.Text;

            for (int i = 0; i < CalculationProgress.Length; i++)
            {
                if (CalculationProgress[i].ToString() == "+")
                {
                    LastOperatorUsedByUser = "******";
                }
                else if (CalculationProgress[i].ToString() == "-")
                {
                    LastOperatorUsedByUser = "******";
                }
                else if (CalculationProgress[i].ToString() == "/")
                {
                    LastOperatorUsedByUser = "******";
                }
                else if (CalculationProgress[i].ToString() == "*")
                {
                    LastOperatorUsedByUser = "******";
                }
            }

            //Storing the current number which is inside the tbINputNumbers textblock,Adding current number to Memory array
            //Incrementing MemoryIndex by one
            //Storing the calculation in the result variable (Rounding the result)
            //Adding result to Memory and ResultMemory
            //Incrementing the navigator by one and setting the navigator on this side to the new value
            //User cannot delete last number of the result, setting NoCalculationsYet to false as we've just calculated

            CurrentNumber = Convert.ToDouble(TbInputNumbers.Text);

            Calculations.AddToMemory(CurrentNumber);
            Result = Calculations.Summarize(LastOperatorUsedByUser);
            Calculations.IncrementMemoryIndexByOne();
            Math.Round(Result, 10);

            Calculations.AddToMemory(Result);
            Calculations.AddToResultMemory(Result);
            Calculations.IncrementResultMemoryIndexByOne();
            Calculations.GiveBackResultMemoryValues();

            Calculations.IncrementResultMemoryNavigatorByOne();

            UserCanDeleteLastNumber = true;
            NoCalculationsYet       = false;

            //Setting this variable to false as the user can use division or multiplication, because the Memory array is not empty
            NewCalculation = false;

            //Setting the ResultMemory textblocks's text to the result

            TbResultMemory.Text = Result.ToString();

            //After the calculation this variable will always be one
            CalculationIsOnGoing = 1;

            //Setting the TbCalculationProgress's text to default
            TbCalculationProgress.Text = "";

            //Setting the TbInputNumbers Textblock's text to default after every calculation
            TbInputNumbers.Text = "0";
        }