// Implementation file for the MathStack class
#include "MathStack.h"

//***********************************************
// Member function add. add pops                *
// the first two values off the stack and       *
// adds them. The sum is pushed onto the stack. *
//***********************************************

void MathStack::add()
{
   int num, sum;

   // Pop the first two values off the stack.
   pop(sum);
   pop(num);

   // Add the two values, store in sum.
   sum += num;

   // Push sum back onto the stack.
   push(sum);
}

//***********************************************
// Member function sub. sub pops the            *
// first two values off the stack. The          *
// second value is subtracted from the          *
// first value. The difference is pushed        *
// onto the stack.                              *
//***********************************************

void MathStack::sub()
{
   int num, diff;

   // Pop the first two values off the stack.
   pop(diff);
   pop(num);

   // Subtract num from diff.
   diff -= num;

   // Push diff back onto the stack.
   push(diff);
}
// Added function 
//multiplication
//***********************************************
// Member function mult. mult pops the          *
// first two values off the stack. 		        *
// The two values is multiplied        		    *
// The results is pushed to the stack           *
// onto the stack.                              *
//***********************************************

void MathStack::mult()
{
  int num1, num2;

  // show two numbers 
  pop(num1);
  pop(num2);

  // push the stack for multiplcation
  push(num1 * num2);
}
//Division function
//multiplication
//***********************************************
// Member function div. div pops the            *
// first two values divided . 		            *
// Second value in the stack is divide over 1st *        		    *
// The results is pushed to the stack           *
// onto the stack.                              *
//***********************************************
void MathStack::div()
{
  int num1, num2;

  // show the two numbers 
  pop(num1);
  pop(num2);

  push(num2 / num1);
  // Push the number quotient
}

void MathStack::addAll()
{
	//check add oparator 
  int sum = 0, temp;

  while (!isEmpty())
  {
    pop(temp);
    sum += temp;
  }

  push(sum);
}

void MathStack::multAll()
{
	//check devison operator 
  int product = 0, temp;

  while (!isEmpty())
  {
    pop(temp);
    product *= temp;
  }

  push(product);
}