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? For example, can you add -1/4 ...
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