// // main.m // a+b // #import <Foundation/Foundation.h> #import "Calcultor.h" int main(int argc, const char * argv[]) { Calcultor * cal = [[Calcultor alloc]init]; [cal setA:10]; [cal setB:20]; int result = [cal add]; NSLog(@"%d",result); NSLog(@"%d",[cal sub:10 andb1:10]); return 0; }
// // Calcultor.h // a+b // #import <Foundation/Foundation.h> @interface Calcultor : NSObject { int _a; int _b; } /*set get */ @property int a; @property int b; -(int)add; -(int)sub:(int)a1 andb1:(int)b1; @end
// // Calcultor.m // a+b // #import "Calcultor.h" @implementation Calcultor -(id)init { self = [super init]; if(self != nil) { _a = 0; _b = 0; } return self; } -(int)add { return _a + _b; //NSLog(@"a+b"); } -(int)sub:(int)a1 andb1:(int)b1; { _a = a1; _b = b1; return _a + _b; } @end