#include #include "Fraction.h" using namespace std; // fill in all of the Fraction class methods here // reduce - When called will cause the fraction to reduce itself to it lowest terms. For example // if the fraction is 4/8 3/6 5/10 or 1/2 these will all be reduced to 1/2 after call to this // method. // param // none // returns // void void Fraction::reduce() { int divisor; divisor = gcd(n, d); n = n / divisor; d = d / divisor; } // gcd - This is a private method of the Fraction class that does the actual work of finding the greatest // common denominator (gcd) that can be used as a divisor to reduce a fraction to its simplest terms. // This function implements an algorithm known as Euclids method for finding the gcd. This is an example // or a recursive function, can you figure out how it works? // param // int - n The neumerator of the fraction to find the gcd // int - d The denominator of the fraction to find the gcd // returns // int - The greatest common denominator, for example if n=4 and d=8, gcd is 4 (because both 4 and 8 can be // divided by 4 and this is the largest such number that is a divisor of both n and d). int Fraction::gcd(int n, int d) { if (d == 0) return n; return gcd(d, n % d); }