下面是代码,我还在这里附加了一个完整项目的链接:
(谢谢)
http://files.me.com/knyck2/svpfd4
//// Calculator_trig.m// 11.4_calculator_trig//// Created by Nicholas Iannone on 1/6/10.// copyright 2010 __MyCompanyname__. All rights reserved.//#import "Calculator_trig.h"#import <math.h>@implementation Calculator (Trigonometry)-(double) sin{ double result; result = (double) sin (accumulator); return result;}-(double) cos{ double result; result = cos ( accumulator); return result;}-(double) tan{ double result; result = tan ( accumulator); return result;}@end #import "Calculator.h"@implementation Calculator-(voID) setAccumulator: (double) value{ accumulator = value;}-(voID) clear{ accumulator = 0;}-(double) accumulator{ return accumulator;}-(double) memoryClear{ memory = 0; NSLog(@"memory has been cleared"); return accumulator;}-(double) memoryStore{ memory = accumulator; NSLog(@"memory has been set to %g",memory); return accumulator;}-(double) memoryRecall{ accumulator = memory; NSLog(@"accumulator has been set to %g",accumulator); return accumulator;}-(double) memoryAdd{ memory += accumulator; NSLog(@"accumulator: %g has been added to memory,memory is Now %g",accumulator,memory); return accumulator;}-(double) memorySubtract{ memory -= accumulator; NSLog(@"accumulator: %g has been subtracted from memory,memory); return accumulator;}-(double) add: (double) value{ accumulator += value; return accumulator;}-(double) subtract: (double) value{ accumulator -= value; return accumulator;}-(double) multiply: (double) value{ accumulator *= value; return accumulator;}-(double) divIDe: (double) value{ accumulator /= value; return accumulator;}-(double) changeSign{ accumulator = -accumulator; return accumulator;}-(double) reciprocal{ accumulator = 1 / accumulator; return accumulator;}-(double) xSquared{ accumulator *= accumulator; return accumulator;}@end #import <Foundation/Foundation.h>#import "Calculator.h"#import "Calculator_trig.h"int main (int argc,const char * argv[]) { NSautoreleasePool * pool = [[NSautoreleasePool alloc] init]; Calculator *myCalc = [[Calculator alloc] init]; double a = 0; [myCalc setAccumulator: 100.70]; a = [myCalc sin]; NSLog(@" sin of accumulator = %f",a); [myCalc release]; [pool drain]; return 0;}解决方法 你正在计算100.7弧度的罪,给出的答案是正确的. 总结
以上是内存溢出为你收集整理的objective-c – 为什么这个sin方法会回答错误的答案?全部内容,希望文章能够帮你解决objective-c – 为什么这个sin方法会回答错误的答案?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)