示例#1
0
        private void BtnDivide_Click(object sender, EventArgs e)
        {
            f1 = new MixedFraction(Convert.ToInt32(txtWhole1.Text), Convert.ToInt32(num1.Text), Convert.ToInt32(den1.Text));
            f2 = new MixedFraction(Convert.ToInt32(txtWhole2.Text), Convert.ToInt32(num2.Text), Convert.ToInt32(den2.Text));

            // used before mixed fractions
//            f1 = new Fraction(Convert.ToInt32(num1.Text), Convert.ToInt32(den1.Text));
//            f2 = new Fraction(Convert.ToInt32(num2.Text), Convert.ToInt32(den2.Text));

            answer = new MixedFraction();
            answer.Divide(f1, f2);

            // get mixed fractions for first and second entered fractions, print out as string
            MixedFraction mixedFraction1 = new MixedFraction();
            MixedFraction mixedFraction2 = new MixedFraction();

            mixedFraction1.ToMixedFraction(f1);
            mixedFraction2.ToMixedFraction(f2);

            labelFraction1.Text = mixedFraction1.GetMixedString();
            labelFraction2.Text = mixedFraction2.GetMixedString();

            // Convert improper Fraction to mixed fraction
            MixedFraction mixedAnswer = new MixedFraction();

            mixedAnswer.ToMixedFraction(answer);

            lblResult.Text = mixedAnswer.GetMixedString();

            txtWholeResult.Text = Convert.ToString(mixedAnswer.GetWhole());
            numResult.Text      = Convert.ToString(mixedAnswer.GetMixedNumerator());
            denResult.Text      = Convert.ToString(mixedAnswer.GetMixedDen());
        }
示例#2
0
        private void BtnDivide_Click(object sender, EventArgs e)
        {
            f1 = new Fraction(Convert.ToInt32(num1.Text), Convert.ToInt32(den1.Text));
            f2 = new Fraction(Convert.ToInt32(num2.Text), Convert.ToInt32(den2.Text));

            answer = new Fraction();
            answer.Divide(f1, f2);

            numResult.Text = Convert.ToString(answer.GetNumerator());
            denResult.Text = Convert.ToString(answer.GetDenominator());

            lblResult.Text = answer.GetString();
        }
示例#3
0
        private void BtnDivide_Click(object sender, EventArgs e)
        {
            // Verify Number will parse our entries. This version will use TryParse in the method VerifyNumbers().
            String badEntry = VerifyNumbers();


            // if VerifyNumbers didn't' null, it found bad character, break out of method and return to main for user to fix.
            if (badEntry != null)
            {
                labelResults.Text = "You entered an invalid number. Please enter a valid integer. Bad entry: " + badEntry;
                return;
            }

            f1 = new MixedFraction(Convert.ToInt32(txtWhole1.Text), Convert.ToInt32(num1.Text), Convert.ToInt32(den1.Text));
            f2 = new MixedFraction(Convert.ToInt32(txtWhole2.Text), Convert.ToInt32(num2.Text), Convert.ToInt32(den2.Text));


            answer = new MixedFraction();
            answer.Divide(f1, f2);

            // get mixed fractions for first and second entered fractions, print out as string
            MixedFraction mixedFraction1 = new MixedFraction();
            MixedFraction mixedFraction2 = new MixedFraction();

            mixedFraction1.ToMixedFraction(f1);
            mixedFraction2.ToMixedFraction(f2);

            labelFraction1.Text = mixedFraction1.GetMixedString();
            labelFraction2.Text = mixedFraction2.GetMixedString();

            // Convert improper Fraction to mixed fraction
            MixedFraction mixedAnswer = new MixedFraction();

            mixedAnswer.ToMixedFraction(answer);

            lblResult.Text = mixedAnswer.GetMixedString();

            txtWholeResult.Text = Convert.ToString(mixedAnswer.GetWhole());
            numResult.Text      = Convert.ToString(mixedAnswer.GetMixedNumerator());
            denResult.Text      = Convert.ToString(mixedAnswer.GetMixedDen());
            labelResults.Text   = ("All your numbers were valid!");
        }