#import <Foundation/Foundation.h>
@interface Calculator : NSObject
+(void)add:(int)num1 andNmu2:(int)num2;
+(void)jian:(int)num1 andNmu2:(int)num2;
+(void)cheng:(int)num1 andNmu2:(int)num2;
+(void)chu:(int)num1 andNmu2:(int)num2;
@end
#import "Calculator.h"
@implementation Calculator
+(void)add:(int)num1 andNmu2:(int)num2{
NSLog(@"两数相加得%d",num1+num2);
}
+(void)jian:(int)num1 andNmu2:(int)num2{
NSLog(@"两数相减得%d",num1-num2);
}
+(void)cheng:(int)num1 andNmu2:(int)num2{
NSLog(@"两数相乘得%d",num1*num2);
}
+(void)chu:(int)num1 andNmu2:(int)num2{
NSLog(@"两数相除得%.2f",(float)num1/num2);
}
@end
#import <Foundation/Foundation.h>
#import "Calculator.h"
int main(int argc, const char * argv[]) {
@autoreleasepool {
[Calculator add:17 andNmu2:7];
[Calculator jian:27 andNmu2:17];
[Calculator cheng:37 andNmu2:27];
[Calculator chu:47 andNmu2:37];
}
return 0;
}
|