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.
Program 21.2. Fraction.h Interface 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;-(NSString *) convertToString; ...
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