Created
April 23, 2011 18:47
-
-
Save wanewang/938866 to your computer and use it in GitHub Desktop.
objc number
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
#import <Foundation/Foundation.h> | |
@interface Number : NSObject{ | |
double real; | |
double imaginary; | |
} | |
-(void) setReal : (double) r; | |
-(void) setImaginary : (double) i; | |
-(void) setAll : (double) r: (double) i; | |
-(void) print; | |
@end | |
@implementation Number | |
-(void) setReal : (double) r{ | |
real = r; | |
} | |
-(void) setImaginary : (double) i{ | |
imaginary = i; | |
} | |
-(void) setAll:(double)r :(double)i{ | |
real = r; | |
imaginary = i; | |
} | |
-(void) print{ | |
NSLog(@"%g+%gi\n",real,imaginary); | |
} | |
@end | |
int main (int argc, const char * argv[]) | |
{ | |
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; | |
Number * num = [[Number alloc] init]; | |
[num setReal:2]; | |
[num setImaginary:3.7]; | |
[num print]; | |
[num setAll:3.5 :0.8]; | |
[num print]; | |
[num release]; | |
[pool drain]; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment