示例#1
0
        public override bool Equals(object obj)
        {
            bool     result = false;
            Fraction f1     = new Fraction(this.numerator, this.denominator);
            Fraction f2     = (Fraction)obj;
            Fraction f4;
            Fraction f5;

            if (f1.denominator != f2.denominator)
            {
                f1.GreatestCommonDenominator(f1, f2, out f4, out f5);
            }
            else
            {
                f4 = f1;
                f5 = f2;
            }

            if (f4.numerator == f5.numerator)
            {
                result = true;
            }

            return(result);
        }
示例#2
0
        /*******************************************
        * Math operators + - * /
        * *****************************************/
        public static Fraction operator +(Fraction f1, Fraction f2)
        {
            Fraction f3 = new Fraction();
            Fraction f4; //these recieve values from the out parameters
            Fraction f5;

            if (f1.denominator != f2.denominator)
            {
                //the denominators don't match
                //get the greatest common denominator
                //the out parameters provide a way of returning
                //more than one value from a method
                f3.GreatestCommonDenominator(f1, f2, out f4, out f5);
            }
            else
            {
                //if they do match we still need to assign
                //the values to the new fractions so we
                //can do the math below
                f4 = f1;
                f5 = f2;
            }


            f3.denominator = f4.denominator;

            f3.numerator = f4.numerator + f5.numerator;

            //reduce the resulting fraction
            f3 = f3.ReduceFraction(f3);

            return(f3);
        }
示例#3
0
        public static Fraction operator -(Fraction f1, Fraction f2)
        {
            Fraction f3 = new Fraction();
            Fraction f4;
            Fraction f5;

            if (f1.denominator != f2.denominator)
            {
                f3.GreatestCommonDenominator(f1, f2, out f4, out f5);
            }
            else
            {
                f4 = f1;
                f5 = f2;
            }


            f3.denominator = f4.denominator;

            f3.numerator = f4.numerator - f5.numerator;

            f3 = f3.ReduceFraction(f3);

            return(f3);
        }