Professional Documents
Culture Documents
Order of Precedence
() Function call
- Unary minus
+ Unary plus
++ Increment
-- Decrement
! Logical negation
& Address
* Multiplication
% Modulus
- Subtraction
!= Inequality
#import <Foundation/Foundation.h>
[pool drain];
return 0;
}
September 03, 2009
// accumulator methods
-(void) setAccumulator: (double) value;
-(void) clear;
-(double) accumulator;
// arithmetic methods
-(void) add: (double) value;
-(void) subtract: (double) value;
-(void) multiply: (double) value;
-(void) divide: (double) value;
@end
September 03, 2009
@implementation Calculator
-(void) setAccumulator: (double) value
{
accumulator = value;
}
-(void) clear
{
accumulator = 0;
}
-(double) accumulator
{
return accumulator;
}
[deskCalc clear];
[deskCalc setAccumulator: 100.0];
[deskCalc add: 200.];
[deskCalc divide: 15.0];
[deskCalc subtract: 10.0];
[deskCalc multiply: 5];
NSLog (@"The result is %g", [deskCalc accumulator]);
[deskCalc release];
[pool drain];
return 0;
}
September 03, 2009
September 03, 2009
September 03, 2009
September 03, 2009
We're not working with Cocoa here, so change the line in the file Fraction.h that reads
#import <Cocoa/Cocoa.h>
to read
#import <Foundation/Foundation.h>
September 03, 2009
-(void) print;
-(double) convertToNum;
@end
#import "Fraction.h"
@implementation Fraction
A method to set both the numerator and the denominator could be named setNumerator:andDenominator: , and
you might use it like this:
[myFraction setNumerator: 1 andDenominator: 3];