Fraction Equality by Value (operator==)
mediumQuestion 75You are comparing ingredient ratios, and 5/10 should equal 1/2 (both represent the same value).
Create a class Fraction that stores TWO ints: numerator and denominator.
Important: - Do NOT reduce/simplify the fraction in the constructor. Store the values as-is. - To compare fractions for equality, compare their VALUE using cross-multiplication.
Requirements:
1) Constructor Fraction(int numerator, int denominator)
2) Getters getN() const, getD() const
3) Overload operator== so two fractions are equal if n1*d2 == n2*d1
Assume denominator is never 0. Do NOT write a main function.
Expected output
equal not equal
= newline. The output ends with a newline, so print one after the last line.
Hints2 available
Sign in to use hintsTopics
ClassesOperator Overloading
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (cout, fori)
Your output
Run your code to see the output here...
Test cases
Run your code to see test case results.