I have an assignment of the following.

Create a class named Fractions having two integer data members named for a fraction’s numerator and denominator. The Class’s default constructor should provide both data members with default values of 1 if no explicit user initialization is provided. The constructor must also prohibit a 0 denominator value. Additionally, provide member functions for displaying an object’s data values. Also provide the class with overloaded operators that are capable of adding, subtracting, multiplying and dividing two Fraction objects according to the following formulas:

Sum of two fractions: a/b + c/d = ad + cb
Difference of two fractions: a/b – c/d = ad – cb

Product of two fractions a/b X c/d = ac
Division of two fractions: a/b / c/d = ad

To be fairly honest with you, I don't even know where to begin on this. I will toy with it and post what I have and hope you guys can help me.

Thank you

class Fractions


     //class constructor
     Fractions( );

     //overloaded operators
     Fraction operator+(const Fraction &rhs);
     Fraction operator-(const Fraction &rhs);
     Fraction operator/(const Fraction &rhs);
     Fraction operator*(const Fraction &rhs);

     void print( );


     int numerator;
     int denominator;

This is about all the help I can give ye' for now.. Above is an example class that should get you started.. all you have to do is write the functions. :cool:

This article has been dead for over six months. Start a new discussion instead.