#include<iostream>
//#include<stdlib>
#include<Math.h>
#include"CA_STACK.h"


template<class T>
class Calculater
{
public:
 Calculater();     //construction
 void Run();      //calculate
 void Calculate(char charOper );
 int JudgeRunCondition();
 void GetTowOperater();//在满足条件的情况下取
 void GiveTips();
 stack_node<T> sta;
private:

 T oper1,oper2;
};


template<class T>
Calculater<T>::Calculater()
{
 oper1 = 0;
 oper2 = 0;
}
template<class T>
int Calculater<T>::JudgeRunCondition()
{
 if(sta.Length() >= 2)
 {
  return 1;
 }
 else
 {
  return 0;
 }
}

template<class T>
void Calculater<T>::GetTowOperater( )
{
 if(JudgeRunCondition() )
 {
  oper2 = sta.Push(),
   oper1 = sta.Push(),
 }
 else
 {
  cout<<"Lack of calculater,Can not calculate!"<<endl;
 }

}


template<class T>
void Calculater<T>::Calculate ( char charOper )

 T a,b;
 a = sta.Pop();
 b = sta.Pop();
 T sum ;
 T minus;
 T mult;
 T divd;
 T power;
 
 /*char charOper;
 cin>>charOper;*/
  switch(charOper)
 {
  case '+': sum =  a+b;
         sta.Push(sum);
      cout<<a <<" + "<<b<<" = " ;
      cout<<sta.Top_data()<<endl;
      break; 
           
  case '-': minus =  a - b;
         sta.Push(minus);
      cout<<a <<" - "<<b<<" = ";
      cout<<sta.Top_data()<<endl ;
      break;
           
  case '*':  mult =  a*b;
        sta.Push( mult);
     cout<<a <<" * "<<b<<" = " ;
      cout<<sta.Top_data()<<endl;
      break;

     case '/':   divd = a/b;
      sta.Push( divd);
      cout<<a <<" / "<<b<<" = " ;
      cout<<sta.Top_data()<<endl;
      break; 
  
  case '^':  power = pow( float(a),int(b));
          sta.Push(power );
       cout<<a <<" ^ "<<b<<" = " ;
       cout<<sta.Top_data()<<endl;
       break;
 }


}


template<class T>
void Calculater<T>::Run()
{  
 char charOper[200];
 while( cin>>charOper,*charOper != 'q')
 { 

  switch(*charOper)
  {
  case '+' : Calculate (  '+' );
           break;

  case '-' :  Calculate (  '-' );
   break;

  case '*' :  Calculate (  '*' );
   break;

  case '/' :    Calculate (  '/' );
   break;

  case '^' :   Calculate (  '^' );
   break;

  default : sta.Push( atoi(charOper) );
   cout<<"the length: "<<sta.Length()<<endl;
   break;
  }
 }
 cout<<"The end of the run"<<endl;
}
template<class T>
void Calculater<T>::GiveTips()
{
cout<<"**************************  calculater  ****************************************"<<endl;
cout<<"Tips:"<<endl;
cout<<"1 YOU SHOULD ENTER TOW OPERATER NUMBER , THE RESULT IS MEMORYDE ,IF YOU WANT COUPUTER A "<<endl;
cout<<" 如果你想在前结果上在进行计算,仅仅输入被操作数即可,若想再计算,但不基于前结果"<<endl;
cout<<"按“C” 进行清除,再操作。"<<endl;
cout<<"2本计算器只能进行五种运算 sumery minus multiply dividel power "<<endl;
cout<<"3 输入时每给操作数与操作符之间用空格隔开 按SPACE OR ENTER 键"<<endl;

cout<<"4  先输入操作数  后输入操作符号。比如实现 1 + 2 你必须先输 1  2  +"<<endl;

cout<<"**************************  calculater  ****************************************"<<endl;

 

}