Solution: Make the Unit Tests Pass

Here’s a solution to the operator overloading challenge for Fractions.

We'll cover the following

Solution

The following implementation passes all of the unit tests. The design decisions have been included as code comments.

Some of the functions of this struct can be implemented to run more efficiently. Additionally, it would be beneficial to normalize the numerator and denominator. For example, instead of keeping the values 20 and 60, the values could be divided by their greatest common divisor and the numerator, and the denominator can be stored as 1 and 3 instead. Otherwise, most of the operations on the object would cause the values of the numerator and the denominator to increase.

Get hands-on with 1000+ tech skills courses.