/*Objective_C Implementation of the RPNCalculator Class: RPNCalculator.m*/

#import <stdio.h>
#import "RPNCalculator.h"

@implementation RPNCalculator
 
 //Initialize a new RPNCalculator instance
-init
{
	stack = [[Stack alloc] init];
	return [super init];
}	
																   
// Enter a number
-(float)enter:(float)number
{
	[stack push:number];
	return [stack top];
}

//Add new entry
-(float)add:(float)number
{
	[stack push:number];
	return [self add];
}

//Add two elements
-(float)add
{
	[stack push: ( [stack  pop] +  [stack  pop]) ];
	return [stack top];
}

//Subtract new entry
-(float)subtract:(float)number
{
	[stack push:number];
	return [self subtract];
}

//Subtract two elements
-(float)subtract
{
	[stack push: ( -[stack  pop] +  [stack  pop]) ];
	return [stack top];
}

// Print the calculator's stack
-printStack
{
	[stack printStack];
	return self;
}

// Empty the calculator's stack
-allClear
{
	[stack empty];
	return self;
}

// Free the calculator and its  stack
-free
{
	[stack free];
	return [super free];
}
@end
