Part of my assignment is to use my professor's .cpp file. In it, I should be able to handle A = A + B where A and B are two fractions.
&Fraction Fraction::operator+(Fraction b)
{
num = (num * b.denom) + (num * denom);///////
denom = (denom * b.denom);
if ((num * denom) >= 0)
{
sign_factor = 1;
}
else
{
sign_factor = -1;
}
num = sign_factor * abs(num);
denom = sign_factor * abs(denom);
num = (num / (static_cast<double>(find_gcd(num, denom))));
denom = (denom / (static_cast<double>(find_gcd(num, denom))));
return this;
}
My question is how I would return the object A so that main.cpp can perform member assignment (assigning the result of A+B to A). Also, is it correct that I referred to num inside this function, or should I use a.num. For example, should it be "a.num = sign_factor * abs(num) or is what I have okay?
Thankyou very much!!