Programming in C

(Barry) #1
Defining an Objective-C Class to Work with Fractions 415

//------- @interface section -------


@interface Fraction: Object
{
int numerator;
int denominator;
}
-(void) setNumerator: (int) n;
-(void) setDenominator: (int) d;
-(void) print;


@end


//------- @implementation section -------


@implementation Fraction;


// getters


-(int) numerator
{
return numerator;
}


-(int) denominator
{
return denominator;
}
// setters


-(void) setNumerator: (int) num
{
numerator = num;
}


-(void) setDenominator: (int) denom
{
denominator = denom;
}


// other


-(void) print
{


Program 19.2 Continued
Free download pdf