Hi guys i just started learning Objective-C and i just have a quick question.
heres the program:
(got that outa a txt book.)
and my question is: why does
have to have the arguments n and d?
couldnt you just put it as :
????
why does it need those arguments to set the fraction?
heres the program:
Code:
#import <Foundation/Foundation.h>
@interface Fraction : NSObject
{
int numerator;
int denominator;
}
-(int) numerator;
-(int) denominator;
-(void) print;
-(void) setNumerator: (int) n;
-(void) setDenominator: (int) d;
@end
@implementation Fraction
-(int) numerator
{
return numerator;
}
-(int) denominator
{
return denominator;
}
-(void) print
{
NSLog (@"%i/%i", numerator, denominator);
}
-(void) setNumerator: (int) n;
{
numerator = n;
}
-(void) setDenominator: (int) d;
{
denominator = d;
}
@end
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
Fraction *myFraction = [Fraction new];
[myFraction setNumerator: 1];
[myFraction setDenominator: 3];
NSLog (@"The value of myFraction is: %i/%i",
[myFraction numerator], [myFraction denominator]);
[myFraction release];
[pool drain];
return 0;
}
(got that outa a txt book.)
and my question is: why does
Code:
-(void) setNumerator: (int) n;
-(void) setDenominator: (int) d;
have to have the arguments n and d?
couldnt you just put it as :
Code:
-(void) setNumerator;
-(void) setDenominator;
why does it need those arguments to set the fraction?
Last edited: