Exercises
1. Add the following methods to the Fraction
class to round out the arithmetic operations on fractions. Reduce the result within the method in each case:
// Subtract argument from receiver–(Fraction *) subtract: (Fraction *) f;// Multiply receiver by argument–(Fraction *) multiply: (Fraction *) f;// Divide receiver by argument–(Fraction *) divide: (Fraction *) f;
2. Modify the print
method from your Fraction
class so that it takes an additional BOOL
argument that indicates whether the fraction should be reduced for display. If it is to be reduced (that is if the argument is YES
), be sure not to make any permanent changes to the fraction itself.
3. Will your Fraction
class work with negative fractions? ...
Get Programming in Objective-C, Sixth Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.