← Back to Classes
Question 75
Fraction Equality by Value (operator==)
Fraction Equality by Value (operator==)
You 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) GettersgetN()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 — 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.