欢迎来到天天文库
浏览记录
ID:50828026
大小:33.27 KB
页数:4页
时间:2020-03-15
《OC语言输出分子分母并计算分子分母的和.docx》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、#import@interfaceFraction:NSObject-(void)print;-(void)setNumerator:(int)n;-(void)setDenominator:(int)d;-(int)numerator;-(int)denominator;@end#import"Fraction.h"@implementationFraction{intnumerator;intdenominator;}-(void)print{if(denominator==0)printf
2、("NAN");elseprintf("%i/%i",numerator,denominator);}-(void)setNumerator:(int)n;{numerator=n;}-(void)setDenominator:(int)d;{denominator=d;}-(int)numerator{returnnumerator;}-(int)denominator;{returndenominator;}@end#import#import"Fraction.h"intmain(in
3、targc,constchar*argv[]){@autoreleasepool{//insertcodehere...//NSLog(@"Hello,World!");Fraction*myFraction=[[Fractionalloc]init];//设置分数//输入第一个分数i/jinti,j;printf("请输入i,j的值:");scanf("%d%d",&i,&j);[myFractionsetNumerator:i];[myFractionsetDenominator:j];printf("该分数为:");[myFraction
4、print];//输入第二个分数a/binta,b;printf("请输入a,b的值:");scanf("%d%d",&a,&b);[myFractionsetNumerator:a];[myFractionsetDenominator:b];printf("该分数为:");[myFractionprint];//两个分数的和以分数的形式表达[myFractionsetNumerator:((i*b)+(a*j))];[myFractionsetDenominator:(j*b)];printf("两个分数的和为:");[myFractio
5、nprint];//两个分数的差以分数的形式表达[myFractionsetNumerator:((i*b)-(a*j))];[myFractionsetDenominator:(j*b)];printf("两个分数的差为:");[myFractionprint];//add=((i*b)+(a*j))/(j*b);//red=((i*b)-(a*j))/(j*b);//printf("%i,%i",add,red);}return0;}
此文档下载收益归作者所有