CJCoding With Joseph
15per day

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) 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
Topics:
ClassesOperator Overloading
Code Editor
1
Tab to indent ยท Ctrl+Enter to run ยท 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.