【C++编译】几乎全是【语法错误 : 缺少“;”(在“}”的前面)】 怎么改?
#include<iostream>
using namespace std;
const int maxstack=30;
int count;
int Error_code;
const int MAX_SIZE = 1000;
double a;
double b;
char op;
//表达式基本正确。进行计算(但也有可能会出现“输入错误”提示) [部分]
char ex;
int z;
int i;
int j;
int temp[10];
template<class T,int maxstack> class Stack
{
public:
Stack();
bool empty() const;
bool full() const;
int pop();
int top(T &item) const;
int push(const T &item);
private:
int count;
T entry[maxstack];
T item;
};
//以下为Stack类定义
template<class T,int maxstack> void class Stack<class T,int maxstack>::Stack() //constructor
{count=0;}
template<class T,int maxstack> bool class Stack<class T,int maxstack>::empty() const
{
bool outcome=true;
if(count>0)outcome=false;
return outcome;
}
template<class T,int maxstack> bool class Stack<class T,int maxstack>::full() const
{
bool outcome=false;
if(count=maxstack-1) outcome=true;
return outcome;
}
template<class T,int maxstack> int class Stack<class T,int maxstack>::pop()
{
Error_code outcome=0;
if(count=0)
outcome=-1;
else --count;
return outcome;
}
template<class T,int maxstack> int class Stack<class T,int maxstack>::top(T &item) const //取操作数栈顶元素item
{
Error_code outcome=0;
if(count=0)
outcome=-1;
else item=entry[count-1];
return outcome;
}
template<class T,int maxstack> int class Stack<class T,maxstack>::push(const T &item) //将数据item压入操作数栈
{
Error_code outcome=0;
if(count>=maxtrack)
outcome=1;
else entry[count++]=item;
return outcome;
}
char zh;
int judge(char zh) //判断函数:判断ch(数组元素)是运算符号还是运算数据
{if((zh>='0'&&zh<='9')||zh='.')
return 1; //是运算数据
if(zh='('||zh=')'||zh='+'||zh='-'||zh='*'||zh='/'||zh='#')
return 0; //是运算符号
}
int qiumi(int a,int b); //求幂函数:a的b次幂(既10的b次幂)(目的:将数组转化为十进制数后压栈)
{int a;
int b;
int i;
int temp=1;
for(int i=0;i<b;i++)
{temp*=a;}
return temp;
}
double deci_sim(int t) //求值:将数组转化为十进制数后压栈回运算数据
{int mi[10];
int t;
double operand=0;
for(q=0;t=0;q++,t--)
{
int q;
mi[q]=qiumi(10,q)
operand=operand+temp[t]*mi[q];
}
return operand;
}
double deci_comp(int n)
{int n
double sum;
double mi[10];
double operand_xs; //小数点后面转化成十进制数
for(p=-1;j+1=i;p--)
{
double temp[10];
int p;
mi[p]=qiumi(10,p);
operand_xs=operand_xs+temp[j+1]*mi[p];
j=j+1;
}
sum=deci_sim(n)+operand_xs;
return sum;
}
char ch;
char compare(fuhao.top,char ch) //判断函数:判断运算符栈运算符号的优先级
{int fuhaojudge=2;
if((fuhao.top=='+'&&ch=='+') || (fuhao.top=='+'&&ch=='-') || (fuhao.top=='-'&&ch=='+') || (fuhao.top=='-'&&ch=='-')
|| (fuhao.top=='*'&&ch=='*') || (fuhao.top=='/'&&ch=='/') || (fuhao.top=='*'&&ch=='/') || (fuhao.top=='/'&&ch=='*')
|| (fuhao.top=='*'&&ch=='+') || (fuhao.top=='*'&&ch=='-') || (fuhao.top=='/'&&ch=='+') || (fuhao.top=='/'&&ch=='-')
|| (fuhao.top=='+'&&ch==')') || (fuhao.top=='+'&&ch=='#') || (fuhao.top=='-'&&ch==')') || (fuhao.top=='-'&&ch=='#')
|| (fuhao.top=='*'&&ch==')') || (fuhao.top=='*'&&ch=='#') || (fuhao.top=='/'&&ch==')') || (fuhao.top=='/'&&ch=='#')
|| (fuhao.top==')'&&ch=='+') || (fuhao.top==')'&&ch=='-') || (fuhao.top==')'&&ch=='*') || (fuhao.top==')'&&ch=='/')
|| (fuhao.top==')'&&ch=='(') || (fuhao.top==')'&&ch=='#') )
{fuhaojudge=1
return '>';}
if((fuhao.top=='+'&&ch=='*') || (fuhao.top=='+'&&ch=='/') || (fuhao.top=='+'&&ch=='(') || (fuhao.top=='-'&&ch=='*')
|| (fuhao.top=='-'&&ch=='/') || (fuhao.top=='-'&&ch=='(') || (fuhao.top=='*'&&ch=='(') || (fuhao.top=='/'&&ch=='(')
|| (fuhao.top=='('&&ch=='+') || (fuhao.top=='('&&ch=='-') || (fuhao.top=='('&&ch=='*') || (fuhao.top=='('&&ch=='/')
|| (fuhao.top=='('&&ch=='(') || (fuhao.top=='#'&&ch=='+') || (fuhao.top=='#'&&ch=='-') || (fuhao.top=='#'&&ch=='*')
|| (fuhao.top=='#'&&ch=='/') || (fuhao.top=='#'&&ch=='(') )
{fuhaojudge=-1;
return '<';}
if((fuhao.top=='('&&ch==')') || (fuhao.top=='#'&&ch=='#') )
{fuhaojudge=0;
return '=';}
}
double execute(double a,char op,double b)
{
switch
{case'op='+'':return (b+a);break;
case'op='-'':return (b-a);break;
case'op='*'':return (b*a);break;
case'op='/'':return (b/a);break;
}
}
int main()
{
Stack<char,int> fuhao; //定义运算符栈
Stack<double,int> shu; //定义操作数栈
//函数声明
char zh;
int judge(char zh);
int qiumi(int a,int b);
double deci_sim(int t);
double deci_comp(int n);
char ch;
char compare(fuhao.top,char ch);
double a
double b;
char op;
double execute(a,op,b);
fuhao.push('#'); //将#压入运算符栈栈底
//输入表达式
char array[MAX_SIZE];
char arr[] = "exit";
cout<<"Please input an expression(Ending with #)"<<endl;
cin.getline(array,MAX_SIZE,'\n');
int length=strlen(array);
//判断表达式是否输入正确。若错误,输出“输入有误”
if (array[0]=='+'||array[0]=='-'||array[0]=='*'||array[0]=='/'||array[0]==')'||array[0]=='#')
cout<<"输入有误"<<endl;
int z;
bool judge=false;
for (z=0;z<=length;z++)
{if (((array[z]=='+'||array[z]=='-'||array[z]=='*'||array[z]=='/')&&(array[z+1]=='+'||array[z+1]=='-'||array[z+1]=='*'||array[z+1]=='/'))
||((array[z]=='+'||array[z]=='-'||array[z]=='*'||array[z]=='/'||array[z]=='(')&&(array[z+1]=='#'))
||((array[z]=='+'||array[z]=='-'||array[z]=='*'||array[z]=='/'||array[z]=='(')&&(array[z+1]==')')))
judge=true;
}
for(z=1;z<=length;z++)
if((array[z]=='#')&&(array[z+1]!=NULL))
judge=true;
if(judge)
cout<<"输入有误"<<endl;
//表达式基本正确。进行计算(但也有可能会出现“输入错误”提示)
char ex;
int z;
int i;
int j;
int temp[10];
for (z=0;z<=length;z++)
{
ex=expre[z];
if(judge(ex)) //判断数组元素是运算数据
{
int make=1;
for(i=0;(i<=9)&&(make=1);i++)
{temp[i]=ex;
ex=expre[z+1];
if(judge(ex))
{make=1;z--;};
else
{make=-1;i--;}
}
}
double sum_m;
if {
{for(j=0;j<t;j++)
{if(temp[j]=='.') //判断数组temp中是否有小数点
{{j=j-1;
sum_m=deci_comp(j-1); //有小数点,进入函数deci_comp,进行十进制转换
}
{double deci_sim(i); //无小数点,进入函数deci_sim,进行十进制转换
int t=i;
sum_m=deci_sim(i);
}
shu.push(sum_m);}
else{}
}
else{
if(judge(ex)==0)
{char jisuan;
jisuan=compare(fuhao.top,ex);
switch(jisuan)
{case'<':fuhao.push(ex);
break;
case'=':fuhao.pop();
break;
case'>':double a,b;
char op;
shu.top(a);
shu.top(b);
fuhao.top(op);
double v;
v=execute(a,op,b);
shu.push(v);
break;
default:cout<<"输入有误"<<endl
}}
else{}
}
}
double sum_f;
sum_f=shu.top(); //若运算符栈是两个#,则直接输出操作数栈栈顶
cout<<sum_f<<endl;
return 0;
}
我看了很多说是include 顺序不对 还请高手解答