示例#1
0
        private void BtnSubtract_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));

            answer = new MixedFraction();
            answer.Subtract(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());

            //            numResult.Text = Convert.ToString(answer.GetNumerator());
            //            denResult.Text = Convert.ToString(answer.GetDenominator());
            //
            //            lblResult.Text = answer.GetString();
        }
示例#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 BtnMultiply_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.Multiply(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!");
        }
示例#4
0
        private void BtnAdd_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));

            labelFraction1.Text = f1.GetString();
            labelFraction2.Text = f2.GetString();

            // Console.WriteLine("f1 numerator = " + f1.GetNumerator() + " AND f1 denominator = " + f1.GetDenominator());
            // Console.WriteLine("f2 numerator = " + f2.GetNumerator() + " AND f2 denominator = " + f2.GetDenominator());


            // old school way if operator overloading is not allowed.
            answer = new MixedFraction();
            answer.Add(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();


            //  Demonstration of operator overload use
            //            answer = f1 + f2;

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

            // 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());
        }
示例#5
0
        private void BtnAdd_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));

            Console.WriteLine("f1 numerator = " + f1.GetNumerator() + " AND f1 denominator = " + f1.GetDenominator());
            Console.WriteLine("f2 numerator = " + f2.GetNumerator() + " AND f2 denominator = " + f2.GetDenominator());


            // old school way if operator overloading is not allowed.
            answer = new Fraction();
            answer.Add(f1, f2);


            // Demonstration of operator overload use
//            answer = f1 + f2;


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

            lblResult.Text = answer.GetString();
        }
示例#6
0
        private void BtnAdd_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 return 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;
            }

            // no bad entries found, continue with fraction creation and math!
            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));


//            // If I wanted to use Try/Catch: This code would replace above code. It will print out an error message.
//
//            try
//            {
//                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));
//            }
//            catch (FormatException exception)
//            {
//                labelResults.Text = "Data entered was not valid. Enter valid integers. Error: " + exception.Message;
//                return;
//            }


            labelFraction1.Text = f1.GetString();
            labelFraction2.Text = f2.GetString();

            answer = new MixedFraction();
            answer.Add(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!");
        }