Ejemplo n.º 1
0
 public static Fraction operator *(Fraction frac1, Fraction frac2)
 {
     Fraction frac3 = new Fraction();
     frac3.setA((frac1.num * frac2.num));
     frac3.setB((frac1.den * frac2.den));
     return frac3;
 }
Ejemplo n.º 2
0
 public static Fraction operator +(Fraction frac2, int n)
 {
     Fraction frac6 = new Fraction();
     frac6.setB(frac2.den);
     frac6.setA(frac2.num + frac2.den);
     return frac6;
 }
Ejemplo n.º 3
0
 public static Fraction operator +(Fraction frac1, Fraction frac2)
 {
     Fraction frac5 = new Fraction();
     frac5.setB((frac1.den * frac2.den));
     frac5.setA(((frac1.num * frac2.den) + (frac2.num * frac1.den)));
     return frac5;
 }
Ejemplo n.º 4
0
 public static Fraction operator +(Fraction a,Fraction b)
 {
     Fraction c = new Fraction();
     int lcm = LCM(a.Denom, b.Denom);
     c.setValue(a.Numer * (lcm / a.Denom) + b.Numer * (lcm / b.Denom), lcm);
     return c;
 }
Ejemplo n.º 5
0
 //+ overload
 public static Fraction operator +(Fraction frac, int num )
 {
     Fraction result = new Fraction();
     result.Numer = (num * frac.Demo) + frac.Numer;
     result.Demo = (1) * frac.Demo;
     return result;
 }
Ejemplo n.º 6
0
        public Fraction(Fraction input_Frac)
        {
            _Numer = input_Frac.Numer;
            _Denom = input_Frac.Denom;

            _Count ++;
        }
Ejemplo n.º 7
0
 public static Fraction operator +(Fraction a, Fraction b)
 {
     Fraction c = new Fraction();
     c.Numerator = (a.Numerator * b.Denominator) + (b.Numerator * a.Denominator);
     c.Denominator = (a.Denominator * b.Denominator);
     c.setValue(c.Numerator, c.Denominator);
     return c;
 }
Ejemplo n.º 8
0
        public static Fraction operator +(Fraction x, Fraction y)
        {
            Fraction result = new Fraction();
            result.Numer = x.Numer * y.Denom + y.Numer * y.Denom;
            result.Denom = y.Denom * x.Denom;

            return result;
        }
Ejemplo n.º 9
0
 //fraction+int
 public static Fraction operator +(Fraction f1, int f2)
 {
     int a = 0, b = 0;
     a = (f2 * f1.Denom) + f1.Numer;
     b = f1.Denom;
     Fraction f = new Fraction(a, b);
     f = f.Pudsad(f);
     return f;
 }
Ejemplo n.º 10
0
 public Fraction(Fraction a)
 {
     _Numer = a._Numer;
     if (a.Denom == 0)
         _Denom = 1;
     else
         _Denom = a.Denom;
     _Count++;
 }
Ejemplo n.º 11
0
        public static void Main(string[] args)
        {
            Fraction r1 = new Fraction();
            Fraction r2 = new Fraction(2);
            Fraction r3 = new Fraction(3,9);

            Console.WriteLine ("***** " + Fraction.Count + " Fraction objects have been created *****");

            Fraction r4 = r1+r2;
            Fraction r5 = r2-r3;
            Fraction r6 = new Fraction(100,50);
            r6 += r2;

            //		Fraction r7 = new Fraction(r3);		// case#1
            Fraction r7 = r3;					// case#2
            r7++;

            Console.WriteLine ("***** " + Fraction.Count + " Fraction objects have been created *****");

            Fraction r8 = 10 - (new Fraction(80,40));
            Fraction r9 = (new Fraction(5,25)) + 1;

            Console.WriteLine ("***** " + Fraction.Count + " Fraction objects have been created *****");

            r1.output();
            r2.output();
            r3.output();
            r4.output();
            r5.output();
            r6.output();
            r7.output();
            r8.output();
            r9.output();
            /*Console.WriteLine (r2);
            Console.WriteLine (r3);
            Console.WriteLine (r4);
            Console.WriteLine (r5);
            Console.WriteLine (r6);
            Console.WriteLine (r7);
            Console.WriteLine (r8);
            Console.WriteLine (r9);*/

            Console.WriteLine (r2==r4);
            Console.WriteLine (r4.Equals (r2)); // Equals method must be overriden
            Console.WriteLine (r2!=r4);

            r3.setValue (10,12/3*0);
            r3.output();
            //Console.WriteLine (r3);

            Console.WriteLine ("***** " + Fraction.Count + " Fraction objects have been created *****");

            Console.WriteLine("GCD of 3650 and 360: " + Fraction.GCD (3650,360));
            Console.WriteLine("GCD of 3600 and 360: " + Fraction.GCD (3600,360));
        }
Ejemplo n.º 12
0
 public static Fraction operator +(Fraction f_left, int num)
 {
     Fraction added = new Fraction();
     added.Numer = f_left.Numer + (num * f_left.Denom);
     added.Denom = f_left.Denom;
     return added;
 }
Ejemplo n.º 13
0
 public static Fraction operator +(int num, Fraction f_right)
 {
     Fraction added = new Fraction();
     added.Numer = f_right.Numer + (num * f_right.Denom);
     added.Denom = f_right.Denom;
     return added;
 }
Ejemplo n.º 14
0
 public Fraction(Fraction a)
 {
     Numer = a.Numer / GCD(a.Numer, a.Denom);
     Denom = a.Denom / GCD(a.Numer, a.Denom);
     ++Count;
 }
Ejemplo n.º 15
0
 public static Fraction operator -(Fraction f_left, int num)
 {
     Fraction reduced = new Fraction();
     reduced.Numer = f_left.Numer - (num * f_left.Denom);
     reduced.Denom = f_left.Denom;
     return reduced;
 }
Ejemplo n.º 16
0
 public Fraction(Fraction a)
 {
     numer = a.numer;
     denom = a.denom;
     Count++;
 }
Ejemplo n.º 17
0
 public Fraction(Fraction a)
 {
     Numer = a.Numer;
     Denom = a.Denom;
     Count++;
 }
Ejemplo n.º 18
0
 public bool Equals(Fraction f)
 {
     return(this._numer / this._denom == f.Numer / f.Denom);
 }
Ejemplo n.º 19
0
 public bool Equals(Fraction a)
 {
     return (this.numer / this.denom == a.numer / a.denom);
 }
Ejemplo n.º 20
0
 public bool Equals(Fraction a)
 {
     return (this == a);
 }
Ejemplo n.º 21
0
 public bool Equals(Fraction i)
 {
     return (this.numer / this.decom == i.numer / i.decom);
 }
Ejemplo n.º 22
0
 public Fraction(double numer, double denom)
 {
     this.Numer = numer / Fraction.GCD(numer, denom);
     this.Denom = denom / Fraction.GCD(numer, denom);
     _count++;
 }
Ejemplo n.º 23
0
 public Fraction(Fraction f)
 {
     this.Numer = f.Numer;
     this.Denom = f.Denom;
 }
Ejemplo n.º 24
0
 public static Fraction operator -(int a, Fraction b)
 {
     Fraction c = new Fraction(b);
     c.setValue(a * c.Denom - c.Numer, c.Denom);
     return c;
 }
Ejemplo n.º 25
0
 public bool Equals(Fraction a)
 {
     return (a.numer == this.numer && a.denom == this.denom);
 }
Ejemplo n.º 26
0
 public Fraction(Fraction a)
 {
     setValue(a.Numer, a.Denom);
     _count++;
 }
Ejemplo n.º 27
0
 public bool Equals(Fraction a)
 {
     return(Numer == a.Numer && Denom == a.Denom);
 }
Ejemplo n.º 28
0
 public static Fraction operator +(Fraction a, int b)
 {
     Fraction c = new Fraction(a);
     c.setValue(c.Numer + b*c.Denom, c.Denom);
     return c;
 }
Ejemplo n.º 29
0
 public Fraction(Fraction a)
 {
     setValue(a.Numer,a.Demon);
     _Count++;
 }
Ejemplo n.º 30
0
 public Fraction(Fraction i)
 {
     numer = i.numer;
     decom = i.decom;
     Count++;
 }
Ejemplo n.º 31
0
 public static Fraction operator +(Fraction x , Fraction y)
 {
     Fraction a = new Fraction();
     a.setValue((x.Numer * y.Demon) + (y.Numer * x.Demon), (x.Demon * y.Demon));
     return a;
 }
Ejemplo n.º 32
0
 public Fraction(Fraction a)
 {
     _numer = a._numer;
     _denom = a._denom;
     _count++;
 }
Ejemplo n.º 33
0
 public static Fraction operator +(Fraction x, int y)
 {
     Fraction a = new Fraction();
     a.setValue((x.Numer+(y*x.Demon)), x.Demon);
     return a;
 }
Ejemplo n.º 34
0
 public Fraction(Fraction a)
 {
     numer = a.numer;
     denom = a.denom;
 }
Ejemplo n.º 35
0
 public bool Equals(Fraction c)
 {
     return (numer == c.numer && denom == c.denom);
 }