The Fraction Class
The Fraction
class remains largely unchanged from earlier examples in this text. A new convertToString
method was added to convert a fraction to its equivalent string representation. Program 21.2 shows the Fraction
interface file followed immediately by the corresponding implementation file.
#import <UIKit/UIKit.h>@interface Fraction : NSObject@property int numerator, denominator;-(void) print;-(void) setTo: (int) n over: (int) d;-(Fraction *) add: (Fraction *) f;-(Fraction *) subtract: (Fraction *) f;-(Fraction *) multiply: (Fraction *) f;-(Fraction *) divide: (Fraction *) f;-(void) reduce;-(double) convertToNum; ...
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.