C++ Fractions Class

You may want to start with just the first part, create the class with two constructors, one if they give the two numbers, and one that defaults to 1.

Then, write the four functions, the assignment is nice enough to give you the equations.

If a denominator is ever equal to zero then I would throw an exception, as that is something the user may be able to fix. If you can show what led to it being zero, for example, if they divide (1/2)/(0/4) then your denominator is zero, which should be an error condition.

One issue you will want to look at is if this will be immutable, so, if I have (1/2) and (2/3) and I do an operation, it should return a new number, not modify either of the two that I passed in. In that case your check is always in the constructor for a zero, but you should explain which operation led to this error.

Leave a Comment