Created
February 1, 2019 19:35
-
-
Save yfwu/3bcc7412050c8193fa71f0072bca6c45 to your computer and use it in GitHub Desktop.
prog3-1 <programming in obj-c 6/e>
This file contains 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
**@interface** Fraction: NSObject | |
-(**void**) print; | |
-(**void**) setNumerator: (**int**) n; | |
-(**void**) setDenominator: (**int**) d; | |
**@end** | |
*// ————* | |
**@implementation** Fraction | |
{ | |
**int** numerator; | |
**int** 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, **char** * argv[]) | |
{ | |
**@autoreleasepool** { | |
Fraction *myFraction = [[Fraction alloc] init]; | |
[myFraction setNumerator: 1]; | |
[myFraction setDenominator: 3]; | |
[myFraction print]; | |
} | |
**return** 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment