class Frac
{
public:
// pre-increment
// return a reference to *this
Frac & operator ++ ();
// post-increment (note int dummy parameter)
// return a copy of Frac before updating
Frac operator ++ (int);
// operator== and operator!= are best implemented externally to Frac
// this is so that the first parameter doesn't need to be Frac
friendbooloperator == (const Frac &, const Frac &);
friendbooloperator != (const Frac &, const Frac &);
};
Frac & Frac::operator ++ ()
{
num += den; // just like Frac::addone()
return *this;
}
Frac Frac::operator ++ (int)
{
Frac temp(*this); // make a copy of current Frac
num += den;
return temp;
}
// operator== and operator!= are best implemented externally to Frac
// this is so that the first parameter doesn't need to be Frac if you
// want to compare a Frac to another type
booloperator == (const Frac &lhs, const Frac &rhs)
{
// lhs - left hand side
// rhs - right hand side
if (lhs.num == rhs.num)
return lhs.den == rhs.den;
returnfalse;
}
Well kbw already showed you how to overload operator+.
Operators - * / are overloaded the same way as +, you only need to change the operation accordingly: subtraction, multiplication, division.
Then I showed you post- and pre- increment, and equality and inequality operators.