在这里插入代码#ifndef POINT_H
#define POINT_H#include <string> #include <iostream>using namespace std;template<typename T>class stack{protected: int count=0,n; T* data=new T[n]; 片
```public: stack(); bool empty(); bool full(); T gettop(); void push(const T x); void pop();}; template<typename T>stack<T>::stack(){}template<typename T>bool stack<T>::empty() { if(count==0) return true; else return false;}template<typename T>bool stack<T>::full(){ if(count == n-1) return true; else return false;}template<typename T>T stack<T>::gettop(){ return data[count]; }template<typename T>void stack<T>::push(const T x){ if (full()==false) count++; data[count] = x; return ;}template<typename T>void stack<T>::pop(){ if(empty()==false) count--; }class calcu{ public: calcu(); calcu(string s); int outch(char); int inch(char); int deal(int,int,char); int cal(); private: stack<char>*ch; stack<int>*data; string s; int num1,num2; char fuhao;};calcu::calcu(){}calcu::calcu(string s){ this->s=s;}int calcu::outch(char m){ switch(m) { case'(': return 0; case'+': return 1; case'-': return 1; case'*': return 2; case'/': return 2; case')': return 3;
}
}int calcu::inch(char n){ switch(n) { case'(': return 0; case'+': return 1; case'-': return 1; case'*': return 2; case'/': return 2; case')': return 3; }}int calcu::deal(int num1,int num2,char fuhao){ switch(fuhao) { case'+': return num1+num2; case'-': return num1-num2; case'*': return num1*num2; case'/': return num1/num2; } }int calcu::cal(){ int i,j=0,k,sum; for(i=0;i<s.size();i++) { do { k=s[i]-'0'; j=10*j+k; i++; }while(s[i]>=48); data->push(j); if(s[i]<48) { if(ch->empty()) ch->push(s[i]); if(s[i]==40) ch->push(s[i]); if(s[i]==41) { fuhao=ch->gettop(); num2=data->gettop(); data->pop(); num1=data->gettop(); sum=deal(num1,num2,fuhao); data->push(sum); } else { int out=outch(s[i]); int in=ch->gettop(); if(out>in) { ch->push(s[i]); } else { fuhao=ch->gettop(); num2=data->gettop(); data->pop(); num1=data->gettop(); sum=deal(num1,num2,fuhao); data->push(sum); } } } } return data->gettop();}#endifint main(){ string s; cout<<"请输入一个算式"<<endl; cin>>s; calcu suansi(s); cout<<"结果为"<<endl; cout<<suansi.cal(); return 0;}
不知道为啥算不出来结果,望大佬指教,谢谢