示例#1
0
        private async void Multiply_Click(object sender, RoutedEventArgs e)
        {
            //declare and Gather inputs
            try
            {
                long longAdd1 = long.Parse(InputNumber1.Text);
                long longAdd2 = long.Parse(InputNumber2.Text);

                if (longAdd1 < 0 || longAdd2 < 0)
                {
                    throw new FormatException("Input less than zero");
                }
                if (longAdd1 > 99999999999999999 || longAdd2 > 99999999999999999)
                {
                    throw new FormatException("Input exceeds Soroban maximum value");
                }
                if (longAdd1 * longAdd2 > 99999999999999999)
                {
                    throw new FormatException("Not enough columns to display answer");
                }
                if ((InputNumber1.Text.Length + 1 + (2 * InputNumber2.Text.Length) > 17) && (InputNumber2.Text.Length > InputNumber1.Text.Length))
                {
                    throw new FormatException("Not enough columns to calculate answer. Try switching #1 and #2 around.");
                }
                if (InputNumber1.Text.Length + 1 + (2 * InputNumber2.Text.Length) > 17)
                {
                    throw new FormatException("Not enough columns to calculate answer");
                }
                //Determine the larger input value
                ShowValueOnSoroban(0);
                DisplayTextBox.Text = "";
                string introString = Narratives.GetXMLNarrs("//All_Text_Strings/Main_Text_strings/Multiplication/Introduction");
                introString += Narratives.GetXMLNarrs("//All_Text_Strings/Main_Text_strings/Multiplication/Terminology");

                ContentDialog msgLargest = new ContentDialog()
                {
                    Title           = "Demonstration",
                    Content         = introString,
                    CloseButtonText = "Ok"
                };
                await msgLargest.ShowAsync();

                MultiplyTwoLongs(longAdd1, longAdd2, true);
            }
            catch (FormatException fEx)
            {
                DisplayTextBox.Text = "Error: " + fEx.Message;
            }
            //catch (Exception)
            //{
            //    DisplayTextBox.Text = "Input needs to be an integer between zero and 999999999999\n";
            //}
        }
示例#2
0
        private async void Add_Click(object sender, RoutedEventArgs e)
        {
            //declare and Gather inputs
            try
            {
                long longAdd1 = long.Parse(InputNumber1.Text);
                long longAdd2 = long.Parse(InputNumber2.Text);

                if (longAdd1 < 0 || longAdd2 < 0)
                {
                    throw new FormatException("Input less than zero");
                }
                if (longAdd1 > 99999999999999999 || longAdd2 > 99999999999999999)
                {
                    throw new FormatException("Input exceeds Soroban maximum value");
                }

                //Determine the larger input value
                ShowValueOnSoroban(0);
                DisplayTextBox.Text = "";
                string introString = Math.Max(longAdd1, longAdd2) + " is the larger number. We display this first, and add the smaller number to it.";
                introString += "\nWe add by moving from left to right across the columns of the abacus.\n";
                introString += Narratives.GetXMLNarrs("//All_Text_Strings/Main_Text_strings/Addition/Comment1");

                ContentDialog msgLargest = new ContentDialog()
                {
                    Title           = "Demonstration",
                    Content         = introString,
                    CloseButtonText = "Ok"
                };
                await msgLargest.ShowAsync();

                DisplayTextBox.Text = Math.Max(longAdd1, longAdd2).ToString() + " is displayed on the Soroban above.";
                AddTwoLongsAsync(Math.Max(longAdd1, longAdd2), Math.Min(longAdd1, longAdd2));
            }
            catch (FormatException fEx)
            {
                DisplayTextBox.Text = "Error: " + fEx.Message;
            }
            catch (Exception)
            {
                DisplayTextBox.Text = "Input needs to be an integer between zero and 99999999999999999\n";
            }
        }
示例#3
0
        private async void Subtract_Click(object sender, RoutedEventArgs e)
        {
            //declare and Gather inputs
            try
            {
                long longSubtract1 = long.Parse(InputNumber1.Text);
                long longSubtract2 = long.Parse(InputNumber2.Text);

                if (longSubtract1 < 0 || longSubtract2 < 0)
                {
                    throw new FormatException("Input less than zero");
                }
                if (longSubtract1 > 99999999999999999 || longSubtract2 > 99999999999999999)
                {
                    throw new FormatException("Input exceeds Soroban maximum value");
                }

                //Determine the larger input value
                ShowValueOnSoroban(0);
                DisplayTextBox.Text = "";
                string introString = Narratives.GetXMLNarrs("//All_Text_Strings/Main_Text_strings/Subtraction/Comment2");
                introString += Narratives.GetXMLNarrs("//All_Text_Strings/Main_Text_strings/Subtraction/Comment1");

                ContentDialog msgLargest = new ContentDialog()
                {
                    Title           = "Demonstration",
                    Content         = introString,
                    CloseButtonText = "Ok"
                };
                await msgLargest.ShowAsync();

                DisplayTextBox.Text = Math.Max(longSubtract1, longSubtract2).ToString() + " is displayed on the Soroban above.";
                SubtractTwoLongs(Math.Max(longSubtract1, longSubtract2), Math.Min(longSubtract1, longSubtract2), (longSubtract1 < longSubtract2));
            }
            catch (FormatException fEx)
            {
                DisplayTextBox.Text = "Error: " + fEx.Message;
            }
            catch (Exception)
            {
                DisplayTextBox.Text = "Input needs to be an integer between zero and 99999999999999999\n";
            }
        }
示例#4
0
        public async Task MultiplyTwoLongs(long multiplicand, long multiplier, bool showPopUps)
        {
            int multiplicandStartPos = (multiplier.ToString() + multiplicand.ToString()).Length;

            if (showPopUps)
            {
                ContentDialog msgLargest = new ContentDialog()
                {
                    Title           = "Demonstration",
                    Content         = Narratives.GetXMLNarrs("//All_Text_Strings/Soroban_Text_Strings/MultiplyTwoLongs/Comment1"),
                    CloseButtonText = "Ok"
                };
                await msgLargest.ShowAsync();
            }

            DisplayTextBox.Text = "In our example " + multiplier + " goes to the left and " + multiplicand + " starts " + multiplicandStartPos
                                  + " to the left of the rightmost bar. To begin with it looks like as above.\n";

            long initialDisplay = long.Parse(multiplier.ToString().PadRight((16 - multiplicandStartPos), '0') + multiplicand.ToString().PadRight((1 + multiplicandStartPos), '0'));

            ShowValueOnSoroban(initialDisplay);
            ContinueButton.Visibility = Visibility.Visible;

            int     intLengthOfMultiplier = multiplier.ToString().Length;
            decimal dclToDisplay          = (decimal)initialDisplay;
            long    lngToDisplay          = 0;
            decimal dclShifter            = dcl10ToPower(intLengthOfMultiplier - 2);

            DisplayTextBox.Text += Narratives.GetXMLNarrs("//All_Text_Strings/Soroban_Text_Strings/MultiplyTwoLongs/Comment2");
            int targetColumn = intLengthOfMultiplier + 1;

            //main logic, loop - backwards through each digit of multiplicand
            //uses doubles rather than longs because at some points we have to mutiply results by 0.1
            int t = 1;  // t gets bigger, while i below gets smaller

            for (int i = multiplicand.ToString().Length; i > 0; i--)
            {
                //single digit of the multipliand ***
                decimal dclMultiplicandDigit = decimal.Parse((multiplicand.ToString()).Substring((i - 1), 1));

                //2nd loop - forwards through each digit of the multiplier
                for (int j = 0; j < multiplier.ToString().Length; j++)
                {
                    //single digit of the multiplier ***
                    decimal dclMultiplerDigit = decimal.Parse(multiplier.ToString().Substring(j, 1));
                    decimal dclTens           = dcl10ToPower(t - j);
                    decimal dclProduct        = dclMultiplerDigit * dclMultiplicandDigit;
                    DisplayTextBox.Text += " ...add " + dclProduct.ToString().PadLeft(2, '0') + " (" + dclMultiplerDigit + " x " + dclMultiplicandDigit
                                           + ") to the columns #" + targetColumn + " and #" + (targetColumn - 1) + ",";

                    if (showPopUps)
                    {
                        // try to wait for the button click
                        clickWaitTask = new TaskCompletionSource <bool>();
                        await clickWaitTask.Task;
                    }

                    //adding the product back into the displayed number on Soroban
                    dclToDisplay += dclProduct * dclTens * dclShifter;
                    lngToDisplay  = (long)dclToDisplay;
                    ShowValueOnSoroban(lngToDisplay);
                    targetColumn--;
                }
                DisplayTextBox.Text += "\nClear the end of multiplicand (" + dclMultiplicandDigit + ")... \n";
                targetColumn         = intLengthOfMultiplier + 1 + t;
                dclToDisplay        -= (dclMultiplicandDigit * dcl10ToPower(t + 2) * dclShifter);
                if (showPopUps)
                {
                    // try to wait for the button click
                    clickWaitTask = new TaskCompletionSource <bool>();
                    await clickWaitTask.Task;
                }

                lngToDisplay = (long)dclToDisplay;
                ShowValueOnSoroban(lngToDisplay);
                t++;
            }
            if (showPopUps)
            {
                ContentDialog msgEnd = new ContentDialog()
                {
                    Title           = "Finished",
                    Content         = "All individual products are now summed together.",
                    CloseButtonText = "Ok"
                };
                await msgEnd.ShowAsync();
            }
            //deduct the multipler from far left of the Soroban display
            ShowValueOnSoroban(lngToDisplay - (long.Parse(multiplier.ToString().PadRight(17, '0'))));
            DisplayTextBox.Text      += "\nRemove multiplier, leaves final result: " + (multiplier * multiplicand);
            ContinueButton.Visibility = Visibility.Collapsed;
        }
示例#5
0
 public MainPage()
 {
     this.InitializeComponent();
     DisplayTextBox.Text  = Narratives.GetXMLNarrs("//All_Text_Strings/Main_Text_strings/Introduction/comment1");
     DisplayTextBox.Text += Narratives.GetXMLNarrs("//All_Text_Strings/Main_Text_strings/Introduction/More_info");
 }