Created
June 13, 2009 06:12
-
-
Save jcsalterego/129120 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app | |
*.o |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* A bastardization of: http://www.otierney.net/objective-c.html | |
*/ | |
#import <stdlib.h> | |
#import <stdio.h> | |
#import <Foundation/NSObject.h> | |
@interface Fraction: NSObject { | |
int numerator; | |
int denominator; | |
} | |
-(void) print; | |
-(void) setNumerator: (int) n; | |
-(void) setDenominator: (int) d; | |
-(void) setNumerator: (int) n andDenominator: (int) d; | |
-(int) numerator; | |
-(int) denominator; | |
@end | |
// scope (returnType) methodName: (parameter1Type) parameter1Name; | |
@implementation Fraction | |
-(void) print | |
{ | |
printf("%i/%i", numerator, denominator); | |
} | |
-(void) setNumerator: (int) n | |
{ | |
numerator = n; | |
} | |
-(void) setDenominator: (int) d | |
{ | |
denominator = d; | |
} | |
-(void) setNumerator: (int) n andDenominator: (int) d | |
{ | |
numerator = n; | |
denominator = d; | |
} | |
-(int) denominator | |
{ | |
return denominator; | |
} | |
-(int) numerator | |
{ | |
return numerator; | |
} | |
@end | |
int main (int argc, const char **argv) | |
{ | |
Fraction *frac = [[Fraction alloc] init]; | |
[frac setNumerator: 1]; | |
[frac setDenominator: 3]; | |
[frac setNumerator: 1 | |
andDenominator: 5]; | |
printf("The fraction is: "); | |
[frac print]; | |
printf("\n"); | |
[frac release]; | |
return EXIT_SUCCESS; | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CC=gcc | |
CFLAGS=-Wall | |
LFLAGS=-lobjc -framework Foundation | |
OBJS=main.o | |
app: $(OBJS) | |
$(CC) $(LFLAGS) $(OBJS) -o app | |
main.o: main.m | |
$(CC) -c main.m | |
clean: | |
rm -f *~ *.o app |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment