1 #include <iostream> 2 #include<sstream> 3 using namespace std; 4 template<typename T> 5 class stack 6 { 7 T p[40]; 8 int toop; 9 public: 10 stack() { toop = -1; } 11 void push(T t) { toop++; p[toop] = t; } 12 T top() { return p[toop]; } 13 bool empty() { if (toop == -1)return true; return false; } 14 void pop() { toop--; } 15 }; 16 class caculator 17 { 18 string s;//原波兰式的容器 19 stack<char>op; 20 stack<float>num; 21 stringstream ss;//用于转换的流 22 stringstream sb;//插入逆波兰式的流 23 string str;//存放数字的容器,每次更新 24 string strs;//存放逆波兰式的容器 25 float x, y; 26 public: 27 caculator(char *p) { s = p; } 28 float trans(const char *p); 29 float antipoland(); 30 void show() { cout << strs; } 31 void readnum(); 32 void caucEveTime(); 33 void shownum() { while (!num.empty()) { cout << num.top() << endl; num.pop(); } } 34 void showop() { while (!op.empty()) { cout << op.top() << endl; op.pop(); } } 35 }; 36 float caculator::trans(const char *p)//底层const,对象为常量 37 { 38 float n; 39 n = *p - '