帮我看看哪儿错了?谢谢了~~!
#include "stdafx.h"
#include <iostream>
#include <cctype>
#include <cstring>
using namespace std;
enum PRI{L_Bracket=0,plus=1,minus=1,multiply=2,division=2};
class Info{
public:
void display();
};
class counter
{
private:
void eval_exp1(const double &result);
int len;
public:
counter();
stack opt <char>;
opt.push('# ');
int len = infix.length();
fou(int i=0;i<len;i++){
char ch = infix.at(i);
if (isalnum(ch))// 数字直接输出
{
cout<<ch;
}
else // 操作符就判断并压栈
{
if (ch == '(') // 左括号直接压栈
opt.push(ch);
else if (ch == ')') // 有括号就弹栈到直到遇到左括号
{
ch = opt.top(); // 取得栈顶操作符
while(ch != '(') // 直到弹出左括号
{
OP(ch);
opt.pop();
ch = opt.top();
}
opt.pop(); // 弹出左括号
}
else
{
int thisPri = GetPri(ch); // 当前操作符优先级
char prevOpt = opt.top(); // 上一个操作符
int prevPri = GetPri(prevOpt); // 上一个操作符优先级
while (thisPri <= prevPri)
{ //输出栈中的操作符直到遇到比当前的操作符优先级更低的
OP(prevOpt);
opt.pop(); // 输出后就弹出
prevOpt = opt.top();
prevPri = GetPri(prevOpt);
}
opt.push(ch); //当前操作符压栈
}
}
}
char ch = opt.top(); // 表达式扫描完后把栈中剩余的操作符全部输出
while (ch != '#')
{
OP(ch);
opt.pop();
ch = opt.top();
} ;
void Info::display(){
cout<<"======================================================\n";
cout<<"====================简单计算器========================\n";
cout<<"======================================================\n";
cout<<"* 说明:可以进行+ - * \ ()*\n";
cout<<"* 然后回车 *\n";
cout<<"======================================================\n\n";
}
void counter::eval_exp1(const double &result);
{
register char op;
double temp;
eval_exp1(result);
while((op = *token) == '+' || op == '-' || op == '*' || op == '/' ) {
switch(op) {
case '-':
result = result - temp;
break;
case '+':
result = result + temp;
break;
case '*':
result = result * temp;
break;
case '/':
result = result / temp;
break;
}
}
}