2012-10-01 1 views
1

xcode의 계산기 클래스 작업에 문제가 있습니다. 코드를 참조 용으로 첨부했습니다. 나는 학습 단계에서 초보자이므로 모든 도움을 정말로 받아야한다. 오류는 불완전한 구현의 오류입니다.Xcode의 출력 오류

// Working with Calculator class 
// What required shall be a class where we can perform 4 basic operations of +,-,/,* using accumulator which we can set to some value and perform operations on it and then also return its value, also clear it for some other operation. 

#import <Foundation/Foundation.h> 
@interface Calculator:NSObject 
{ 
    double accumulator;// type of variables employed 

} 
-(void) setAccumulator:(double)value; // Declaring the methods employed 
-(void) clearAccumulator; 
-(double) Accumulator; 
// Method declaration for calculation - Arithematic Methods 
-(void)subtract : (double) value; 
-(void) add : (double) value; 
-(void) multiply : (double) value; 
-(void) divide : (double) value; 
@end 

@implementation Calculator // defining the methods declared in interface section 

-(void) setAccuumulator:(double)value 
{ 
    accumulator=value; 
} 
-(void) clearAccumulator 
{ 
    accumulator = 0; 
} 
-(double) Accumulator 
{ 
    return accumulator; 
} 
-(void) subtract : (double)value 
{ 
    accumulator -= value; 
} 
-(void) add : (double) value 
{ 
    accumulator += value; 
} 
-(void) multiply : (double) value 
{ 
    accumulator *= value; 
} 
-(void) divide : (double) value 
{ 
    accumulator /= value; 
} 
@end 
// Program section as usual begins with the main 
int main(int argc, char*argv[]) 
{ 
    NSAutoreleasePool * pool =[[NSAutoreleasePool alloc] init]; 
    Calculator * deskCal = [[Calculator alloc] init]; 

    [deskCal setAccumulator: 100.0]; 
    [deskCal add :200.0]; 
    [deskCal divide : 15.0]; 
    [deskCal subtract : 10.0]; 
    [deskCal multiply : 5.0]; 

    NSLog(@" The result is %g", [deskCal Accumulator]); 
    [deskCal release]; 
    [pool drain]; 
    return 0; 
} 
+2

'불완전한 구현'을 제공오류가 구현되지 않은 방법을 알려 주어야합니다 - 질문에 오류 출력을 추가 할 수 있습니까? – deanWombourne

+0

@deanWombourne 그는 함수의 철자가 틀렸기 때문에'NSInvalid exception'을 얻고 있습니다. –

+0

나는 함수에 관심이 많았습니다. 질문에서 그것을 볼 수 없었습니다. 당신이 그것을 본 것 같아 보이지만 :) 나는 또한 컴파일러가 잘못되었다고 말하고 있다는 것을 깨닫기를 원했다. – deanWombourne

답변

-2

Xcode에서 전자 수첩 창을 열고 '계산기'를 입력하십시오. 목록에서 샘플 코드 아래의 결과는 '단위 테스트'라는 프로젝트가됩니다. 이 프로젝트를 다운로드하여 빌드 한 다음 구현을 살펴보십시오.

이 프로젝트는 주로 테스트 프레임 워크를 사용하는 방법을 보여주기 위해 설계되었지만 계산기 샘플 앱도 포함되어있어 많은 질문에 답해야합니다. 다른 샘플 코드 및 자습서도이 방법으로 찾을 수 있습니다.

행운을 빈다.

2

당신은

단순히 변경 클래스의 -(void) setAccumulator:(double)value 기능 철자가 당신의 맞춤법이 틀린

-(void) setAccuumulator:(double)value 
{ 
    accumulator=value; 
} 

-(void) setAccumulator:(double)value 
{ 
    accumulator=value; 
} 

이 당신에게

The result is 50