calculate.h- #import <Foundation/Foundation.h>
- @interface calculate : NSObject
- {
- int num1;
- int num2;
- int result;
- }
- +(int)add:(int )num1 andNum2:(int )num2;
- +(int)sub:(int )num1 andNum2:(int )num2;
- +(int)mul:(int )num1 andNum2:(int )num2;
- +(float)div:(int )num1 andNum2:(int )num2;
- @end
复制代码 calculate.m- #import "calculate.h"
- @implementation calculate
- +(int)add:(int )num1 andNum2:(int )num2{
- return num1+num2;
- }
- +(int)sub:(int )num1 andNum2:(int )num2{
- return num1-num2;
- }
- +(int)mul:(int )num1 andNum2:(int )num2{
- return num1*num2;
- }
- +(float)div:(int )num1 andNum2:(int )num2{
- return (float)num1/num2;
- }
- @end
复制代码 main.m- #import <Foundation/Foundation.h>
- #import "calculate.h"
- int main(int argc, const char * argv[]) {
- @autoreleasepool {
- //result=[calculate add:1 andNum2:2];
-
- NSLog(@"%d,%d,%d,%.2f",[calculate add:1 andNum2:2],[calculate mul:1 andNum2:2],[calculate mul:1 andNum2:2],[calculate div:1 andNum2:2]);
- }
- return 0;
- }
复制代码
|
|