Hi Steve and pals,
Here is my solution of Prob. 4.8 - 4.10 , please check it.
If there is any wrong, please let me know, thanks!!

// Prob 4-8, 4-9, 4-10
// Advance Calculator of Ex 4-6
#import <Foundation/Foundation.h>
@interface Calculator : NSObject
{
double accumulator;
double memory;
}
// accumulator methods
-(void) setAccumulator: (double) value;
-(double) clear;
-(double) getAccumulator;
// arithmetic methods
-(double) add: (double) value;
-(double) substract: (double) value;
-(double) multiply: (double) value;
-(double) divide: (double) value;
-(double) changeSign; // change sign of accumulator
-(double) reciprocal; // 1 / accumulator
-(double) xSquared; // accumulator squared
// memory methods
-(double) memoryClear; // clear memory
-(double) memoryStore; // set memory to accumulator
-(double) memoryRecall; // set accumulator to memory
-(double) memoryAdd; // add accumulator to memory
-(double) memorySubstract; // substract accumulator from memory
@end
@implementation Calculator
// accumulator methods
-(void) setAccumulator: (double) value
{
accumulator = value;
}
-(double) clear;
{
return accumulator = 0;
}
-(double) getAccumulator;
{
return accumulator;
}
// arithmetic methods
-(double) add: (double) value;
{
return accumulator += value;
}
-(double) substract: (double) value;
{
return accumulator -= value;
}
-(double) multiply: (double) value;
{
return accumulator *= value;
}
-(double) divide: (double) value;
{
return accumulator /= value;
}
-(double) changeSign; // change sign of accumulator
{
return accumulator = -accumulator;
}
-(double) reciprocal; // 1 / accumulator
{
return accumulator = 1 / accumulator;
}
-(double) xSquared; // accumulator squared
{
return accumulator *= accumulator;
}
// memory methods
-(double) memoryClear; // clear memory
{
return memory = 0;
}
-(double) memoryStore; // set memory to accumulator
{
memory = accumulator;
return accumulator;
}
-(double) memoryRecall; // set accumulator to memory
{
return accumulator = memory;
}
-(double) memoryAdd; // add accumulator to memory
{
return accumulator += memory;
}
-(double) memorySubstract; // substract accumulator from memory
{
return accumulator -= memory;
}
@end
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
Calculator *deskCalcu = [[Calculator alloc] init];
[deskCalcu clear];
[deskCalcu setAccumulator: 5.0];
NSLog(@"Accumulator = %g",[deskCalcu getAccumulator]);
NSLog(@"+ 45, accumulator = %g",[deskCalcu add: 45.0]);
NSLog(@"/ 5, accumulator = %g",[deskCalcu divide: 5.0]);
NSLog(@"- 5, accumulator = %g",[deskCalcu substract: 5.0]);
NSLog(@"* 2, accumulator = %g",[deskCalcu multiply: 2.0]);
NSLog(@"Change sing on accumulator = %g",[deskCalcu changeSign]);
NSLog(@"Reciprocal of accumulator = %g",[deskCalcu reciprocal]);
NSLog(@"Squared of accumulator = %g",[deskCalcu xSquared]);
NSLog(@"Store accumulator to memory, memory = %g", [deskCalcu memoryStore]);
NSLog(@"Reset accumulator, accumulator = %g", [deskCalcu clear]);
NSLog(@"+ 20, accumulator = %g",[deskCalcu add: 20.0]);
NSLog(@"/ 3, accumulator = %g",[deskCalcu divide: 3.0]);
NSLog(@"- 8, accumulator = %g",[deskCalcu substract: 8.0]);
NSLog(@"* 4, accumulator = %g",[deskCalcu multiply: 4.0]);
NSLog(@"Add accumulator to memory, accumulator = %g", [deskCalcu memoryAdd]);
NSLog(@"Store accumulator to memory, memory = %g", [deskCalcu memoryStore]);
NSLog(@"Reset accumulator, accumulator = %g", [deskCalcu clear]);
NSLog(@"+ 7, accumulator = %g",[deskCalcu add: 7.0]);
NSLog(@"/ 10, accumulator = %g",[deskCalcu divide: 10.0]);
NSLog(@"Substract memory from accumulator, accumulator = %g", [deskCalcu memorySubstract]);
NSLog(@"Store accumulator to memory, memory = %g", [deskCalcu memoryStore]);
NSLog(@"Reset accumulator, accumulator = %g", [deskCalcu clear]);
NSLog(@"Recall memory to accumulator, accumulator = %g", [deskCalcu memoryRecall]);
[deskCalcu release];
[pool release];
return 0;
}