//main.m主函数
#import<Foundation/Foundation.h>
#import"Program.h"
#import"Yunsuan.h"
#import"Add.h"
#import"Sub.h"
#import"Mul.h"
#import"Div.h"
int main(intargc,constchar* argv[]) {
@autoreleasepool{
/*
Program *p = [[Program alloc] init];
[p printf:'/' displayConsole:6.0 andB:10.0];
*/
//实例化加法类的对象
Add *a = [[Add alloc]init];
//实例化运算类的对象
Yunsuan *y = [[Yunsuan alloc]init];
//调用对象方法
[yyuansuan:aandNumbera:30andNumberb:2];
//实例化出发类对象
Div *d = [[Divalloc]init];
//调用对象方法
[yyuansuan:dandNumbera:30andNumberb:2];
}
return0;
}
//运算.h文件
#import<Foundation/Foundation.h>
#import"Program.h"
@interface Yunsuan :NSObject
//实例方法的声明
-(void)yuansuan:(Program*)program andNumbera:(double) numbera andNumberb:(double) numberb;
@end
#import"Yunsuan.h"
@implementation Yunsuan
//实例方法的实现
-(void)yuansuan:(Program*)program andNumbera:(double) numbera andNumberb:(double) numberb;
{
//复合
[program GetResultAddSubMulDiv:numbera andNumberB:numberb];
}
@end
//项目类.h文件
#import<Foundation/Foundation.h>
@interface Program :NSObject
//成员变量
@property(assign,nonatomic)double numberA;
@property(assign,nonatomic)double numberB;
//实例方法声明
-(void)GetResultAddSubMulDiv:(double) numbera andNumberB:(double) numberb;
@end
#import"Program.h"
@implementation Program
//实例方法实现
-(void)GetResultAddSubMulDiv:(double) numbera andNumberB: (double) numberb
{
NSLog(@"");
}
@end
//加法.h文件
#import"Program.h"
@interface Add :Program
@end
#import"Add.h"
@implementation Add
//父类方法的重写(多态)
-(void)GetResultAddSubMulDiv:(double) numbera andNumberB:(double) numberb;
{
NSLog(@"结果= %.2f",numbera + numberb);
}
@end
//减法.h文件
#import"Program.h"
@interface Sub :Program
@end
#import"Sub.h"
@implementation Sub
//父类方法的重写(多态)
-(void)GetResultAddSubMulDiv:(double) numbera andNumberB:(double) numberb;
{
NSLog(@"结果= %.2f",numbera - numberb);
}
@end
//乘法.h文件
#import"Program.h"
@interface Mul :Program
@end
#import"Mul.h"
@implementation Mul
//父类方法的重写(多态)
-(void)GetResultAddSubMulDiv:(double) numbera andNumberB:(double) numberb;
{
NSLog(@"结果= %.2f",numbera * numberb);
}
@end
//除法.h文件
#import"Program.h"
@interface Div :Program
@end
#import"Div.h"
@implementation Div
//父类方法的重写(多态)
-(void)GetResultAddSubMulDiv:(double) numbera andNumberB:(double) numberb;{
if(numberb !=0) {
NSLog(@"结果= %.2f", numbera / numberb);
}else{
NSLog(@"除数不能为0");
}
}
@end
请大神指教...