TA的每日心情 | 汗 2024-10-15 10:05 |
---|
签到天数: 372 天 [LV.9]以坛为家II
|
Fraction.h- #import <Foundation/NSObject.h>
-
- @interface Fraction: NSObject
- {
- int numerator;
- int denominator;
- }
-
- -(void) print;
- -(void) setNumerator: (int) n;
- -(void) setDenominator: (int) d;
- -(int) numerator;
- -(int) denominator;
- @end
复制代码
Fraction.m- #import "Fraction.h"
- #import <stdio.h>
- @implementation Fraction
- -(void) print
- {
- printf("%i/%i",numerator,denominator);
- }
-
- -(void) setNumerator: (int) n
- {
- numerator = n;
- }
- -(void) setDenominator: (int) d
- {
- denominator = d;
- }
-
- -(int) denominator
- {
- return denominator;
- }
- -(int) numerator
- {
- return numerator;
- }
- @end
复制代码
main.m- #import <stdio.h>
- #import "Fraction.h"
- int main( int argc, const char *argv[] )
-
- {
- Fraction *frac = [[Fraction alloc] init];
- [frac setNumerator: 1];
- [frac setDenominator: 3];
-
- printf( "The fraction is: " );
- [frac print];
- [frac release];
-
- return 0;
- }
复制代码
|
|