C/C++ Arena

Step 9 of 9

Challenge: a Fraction class

A value type that always keeps itself in a clean form is a great exercise in invariants. Your turn: write class Fraction whose invariant is: always fully reduced, denominator always positive.

std::gcd(a, b) from <numeric> gives the greatest common divisor (it handles negative numbers).

Previous: Keeping invariants