Example #1
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;
 }
Example #2
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;
 }
Example #3
0
 public static Fraction operator -(Fraction frac1, Fraction frac2)
 {
     Fraction frac6 = new Fraction();
     frac6.setB((frac1.den * frac2.den));
     frac6.setA(((frac1.num * frac2.den) - (frac2.num * frac1.den)));
     return frac6;
 }
Example #4
0
 public static Fraction operator ++(Fraction a)
 {
     Fraction frac6 = new Fraction();
     frac6.setB(a.den);
     frac6.setA(a.num + a.den);
     return frac6;
 }
Example #5
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;
 }
Example #6
0
 // obj - int
 public static Fraction operator -(Fraction frac2, int n)
 {
     Fraction frac6 = new Fraction();
     frac6.setB((frac2.den * n));
     frac6.setA(((frac2.num * n) - (frac2.num * n)));
     return frac6;
 }
Example #7
0
 // int - obj
 public static Fraction operator -(int n, Fraction frac2)
 {
     Fraction frac6 = new Fraction();
     frac6.setB(frac2.den);
     frac6.setA((frac2.den * n) - frac2.num);
     return frac6;
 }