This is a friend operator overload function that used addition. It adds two mix fraction by reducing them to simplest form the adding and converting them back to a mixed number
Mixed operator+(const Mixed& f1, const Mixed& f2)
{
int newnum, newnum2, gcd, tmpNumerator2, tmpNumerator, tmpInteger, tmpInteger2;
Mixed r;
tmpNumerator = f1.numerator;
tmpNumerator2 = f2.numerator;
tmpInteger = f1.integer;
tmpInteger2 = f2.integer;
if(tmpInteger < 0)
tmpNumerator *= -1;
if(tmpInteger2 < 0)
tmpNumerator2 *= -1;
newnum = (f1.integer * f1.denominator) + tmpNumerator;
newnum2 = (f2.integer * f2.denominator) + tmpNumerator2;
r.numerator = (newnum * f2.denominator)+ (newnum2 * f1.denominator);
r.denominator = f1.denominator * f2.denominator;
gcd = GCD(r.numerator, r.denominator);
r.numerator /= gcd;
r.denominator /= gcd;
r.integer = r.numerator / r.denominator;
r.numerator = (r.numerator % r.denominator);
return r;
}
I nee to find a way that will not only make this function add f1+f2 but also f1+10,
I think I need to use it as a member function that not only add f1 to f2 but also add f1 to 10 . I have no idea how to do this. if any one know how to please help. Thank you