/*The Fraction + and Fraction / are not being allowed to access private members declared in class Fraction. Any suggestions? */
class Fraction
{
public:
Fraction();
Fraction(int, int);
void setNum(int);
void setDen(int);
int getNum(){return num;}
int getDen(){return den;}
void reduce();
void print(){cout << num <<"/"<< den;}
friend ostream& operator << (ostream& outputstream, Fraction& fraction);
friend istream& operator << (istream& inputstream, Fraction& fraction);
friend Fraction& operator +(Fraction& c);
friend Fraction& operator -(Fraction& c);
friend Fraction& operator *(Fraction& a, Fraction& b);
int Fraction_Do_Op (int operation, Fraction& a, Fraction& b);
private:
int num, den;
int gcd(int, int);
};
#endif
Fraction operator +(Fraction d)
{
int num, den, num2, den2;
Fraction retfrac;
retfrac.num = (num * d.den) + (d.num * d.den);
retfrac.den = d.den * den;
return(retfrac);
}
Fraction operator /(Fraction n, Fraction d)
{
int num, den;
Fraction retfrac;
retfrac.num = num * d.den;
retfrac.den = den * d.num;
if(retfrac.den < 0) //just in case the inversion caused the denominator to be negative
{
retfrac.num *= -1;
retfrac.den *= -1;
}
return(retfrac);
}