/* The class definition for fractions. */ #include #include "Fraction.h" /* <-- notice this */ using namespace std; Fraction::Fraction() /* Default constructor. Initializes fraction to 0/1 */ { numerator = 0; denominator = 1; } Fraction::Fraction(int n, int d) /* initializes fraction to n/d */ { numerator = n; denominator = d; } void Fraction::Input() /* Get a fraction from standard input, in the form "numerator/denominator." */ { char divSign; // used to consume the '/' character during input cin >> numerator >> divSign >> denominator; } void Fraction::Show() /* Display a fraction, in the form "numerator/denominator." */ { cout << numerator << '/' << denominator; } int Fraction::GetNumerator() { return numerator; } int Fraction::GetDenominator() { return denominator; } void Fraction::SetValue(int n, int d) { numerator = n; denominator = d; } double Fraction::Evaluate() /* Calculates and returns the decimal value of a fraction */ { double n = numerator; // convert numerator to double double d = denominator; // convert denominator to double return (n / d); // compute and return float representation }