Exercises
1. Extend the MathOps category from Program 11.1 to also include an invert method, which returns a Fraction that is an inversion of the receiver.
2. Add a category to the Fraction class called Comparison. In this category, add two methods according to these declarations:
-(BOOL) isEqualTo: (Fraction *) f;-(int) compare: (Fraction *) f;
The first method should return YES if the two fractions are identical and should return NO otherwise. Be careful about comparing fractions. (For example, comparing 3/4 to 6/8 should return YES.)
The second method should return –1 if the receiver compares less than the fraction represented by the argument, return 0 if the two are equal, and return 1 if the receiver is greater than the argument.
3. Extend ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access