예제 #1
0
        public static CommonFraction operator *(CommonFraction frac1, CommonFraction frac2)
        {
            CommonFraction res = new CommonFraction(frac1.numerator * frac2.numerator,
                                                    frac1.denominator * frac2.denominator);

            res.ReduceFraction();

            return(res);
        }
예제 #2
0
        private void CountButton_Click(object sender, EventArgs e)
        {
            try
            {
                if (!fraction1.SetValues(Int32.Parse(Num1Box.Text), Int32.Parse(Denom1Box.Text)) ||
                    !fraction2.SetValues(Int32.Parse(Num2Box.Text), Int32.Parse(Denom2Box.Text)) ||
                    !fraction3.SetValues(Int32.Parse(Num3Box.Text), Int32.Parse(Denom3Box.Text)))
                {
                    MessageBox.Show("Denominator mustn't be equaled to 0");
                }
                else
                {
                    fraction1.ReduceFraction();
                    fraction2.ReduceFraction();
                    fraction3.ReduceFraction();

                    result = (fraction1 + fraction2) * (fraction1 - fraction3);

                    taskLine = $"R = (a1/b1 + a2/b2) * (a1/b1 - a3/b3)\nR = ({fraction1} + {fraction2}) * ({fraction1} - {fraction3}) = {result}";

                    taskLine = taskLine.Replace("+ -", "- ");

                    taskLine = taskLine.Replace("- -", "+ ");

                    result.ReverseFraction();

                    taskLine += $"\n1/R = {result}";

                    TaskLabel.Text = taskLine;
                }
            }
            catch (Exception exc)
            {
                MessageBox.Show(exc.Message);
            }
        }