Create a Fraction class in C++

In this project you are to design and build a Fraction class.  This fraction class should following the following class .h file exactly.

class Fraction{
   int num;
   int denom;
   Fraction(); // set num and denom to 0 and 1 resp.
   `Fraction(); // destructor. No big deal here.
   Fraction(n,d); //set num and denom to n and d resp.
   Fraction Add(Fraction f);// add fraction f to the fraction object and return.
   Fraction Mul(Fraction f); // Multiple fraction f time the object and return.
   void Reduce(); // Reduces the objects fraction in situ. ie divide by the gcd(n,denom) 
    //Overloading output operator.  Note that you must put the ostream implementation     // here and not in the .cpp file.  If you put it in the cpp file the     // num in f.num is not recoganized. I believe this is a visual C++ problem     // and not one that occurs in g++ etc.
    friend ostream &operator<<(ostream &output, Fraction &f)
        return output << f.num << "/" << f.denom;
    // Now lets overload the = and other binary mathematical operators
    const Fraction &operator=(const Fraction &);
    friend Fraction operator+(const Fraction, const Fraction);
    friend Fraction operator-(const Fraction, const Fraction);// Not completed
    friend Fraction operator*(const Fraction, const Fraction);
    friend Fraction operator/(const Fraction, const Fraction);
This entry was posted in Algorithms. Bookmark the permalink.

Comments are closed.