// Implementation file for the MathStack class
#include "MathStack.h"
#include <iostream>
using namespace std;

//***********************************************
// 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);
}

void MathStack::multiply()
{
   int num, product;

   // Pop the first two values off the stack.
   pop(product);
   pop(num);

   // multiply the two values, store in product
   product *= num;

   // Push product
   push(product);
}

void MathStack::divide()
{
   int num;
   int result;

   // Pop the first two values off the stack.
   pop(num);
   pop(result);

   // divide the to values
   result =num/result;


   push(result);
   
}

void MathStack::mod()
{
   int num, mod;

   // Pop the first two values off the stack.
   pop(num);
   pop(mod);

   // divide the two items and get the remainder store the remainder
   mod %= num;

   // the result back onto the stack
   push(mod);
}

int main ()
{
	int sum,num,diff,product,mod;
	int result;
	
	int ch;
	
	cout<<"Choose the operation that you want to make.\n ";
	cout<<"1 for addition.\n";
	cout<<"2 for subtracion. \n";
	cout<<"3 for multiplication. \n";
	cout<<"4 for division.  \n";
	cout<<"5 for modulus. \n";
	cout<<"6 to exit the application. \n";
	cin>> ch;
	 
	 if(ch==1)
	 {
	 
		 		cout<<"enter the two numbers that you would like to be added \n";
		 		cin>>num,sum;
		 		int catchVar;  // To hold values popped off the stack

  				 // Create a MathStack object.
  				MathStack stack(5);

  				// Push the two numbers onto the stack.
 				cout << "Pushing "<<num<<"onto the stack \n";
  		 		stack.push(num);
   				cout << "Pushing "<<sum<<"onto the stack \n";
   				stack.push(sum);

  				 // Add the two values.
 				  stack.add();

			    // Pop the sum off the stack and display it.
  				cout << "The sum is ";
   				stack.pop(catchVar);
   				cout << catchVar << endl << endl;

	}
		    
			else if(ch==2){
				
				cout<<"enter the two numbers that you want to find the difference \n";
				cin>>num,diff;
				int catchVar;  // To hold values popped off the stack

  				 // Create a MathStack object.
  				MathStack stack(5);

  				// Push the two numbers onto the stack.
 				cout << "Pushing "<<num<<"onto the stack \n";
  		 		stack.push(num);
   				cout << "Pushing "<<sum<<"onto the stack \n";
   				stack.push(diff);

  				 // subtract the two values.
 				  stack.sub();

			    // Pop the difference off the stack and display it.
  				cout << "The difference is ";
   				stack.pop(catchVar);
   				cout << catchVar << endl << endl;

		 	}
		 	else if(ch==3){
			
				cout<<"enter the two numbers that you want to find the product \n";
				cin>>num,product;
				
			   int catchVar;  // To hold values popped off the stack

  				 // Create a MathStack object.
  				MathStack stack(5);

  				// Push the two numbers onto the stack.
 				cout << "Pushing "<<num<<"onto the stack \n";
  		 		stack.push(num);
   				cout << "Pushing "<<product<<"onto the stack \n";
   				stack.push(product);

  				 // multiply the two values.
 				  stack.multiply();

			    // Pop the product off the stack and display it.
  				cout << "The product is ";
   				stack.pop(catchVar);
   				cout << catchVar << endl << endl;

		 	}
		 	else if(ch==4)
			{
			
				cout<<"enter the two numbers that you want to divide \n";
				cin>>num,result;
					int catchVar;  // To hold values popped off the stack

  				 // Create a MathStack object.
  				MathStack stack(5);

  				// Push the two numbers onto the stack.
 				cout << "Pushing "<<num<<"onto the stack \n";
  		 		stack.push(num);
   				cout << "Pushing "<<result<<"onto the stack \n";
   				stack.push(result);

  				 //  divide the two values.
 				  stack.divide();

			    // Pop the result off the stack and display it.
  				cout << "The result is ";
   				stack.pop(catchVar);
   				cout << catchVar << endl << endl;

		  }
	 	 else if(ch==5){
			
				cout<<"enter the two numbers that you want to find the modulus \n";
				cin>>num,mod;
				int catchVar;  // To hold values popped off the stack

  				 // Create a MathStack object.
  				MathStack stack(5);

  				// Push the two numbers onto the stack.
 				cout << "Pushing "<<num<<"onto the stack \n";
  		 		stack.push(num);
   				cout << "Pushing "<<mod<<"onto the stack \n";
   				stack.push(mod);

  				 // find the modulus of the two values.
 				  stack.mod();

			    // Pop the remainder off the stack and display it.
  				cout << "The  remainder is ";
   				stack.pop(catchVar);
   				cout << catchVar << endl << endl;

		}	//what to do in case user input doest match the choices
		else
		{
			cout<<"invalid choice \n";
		 	exit(0);
		 }
			 
			 
	}
	
			 	
	


