Skip to content

Instantly share code, notes, and snippets.

@wanewang
Created April 23, 2011 18:47
Show Gist options
  • Save wanewang/938866 to your computer and use it in GitHub Desktop.
Save wanewang/938866 to your computer and use it in GitHub Desktop.
objc number
#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