作业帮 > 综合 > 作业

实现带有括号的四则运算

来源:学生作业帮 编辑:百度作业网作业帮 分类:综合作业 时间:2024/04/28 00:06:54
实现带有括号的四则运算
功能要求:输入一个表达式,计算出其正确结果.
例如:输入:123+213-67*34+345/23*45*(34+34-345+245+567)回车
计算结果为:359183
实现带有括号的四则运算
C++的,用VisualC++2005运行.
// EX6_09Extended.CPP
// A program to implement a calculator accepting parentheses
#include // For stream input/output
#include // For the exit() function
#include // For the isdigit() function
#include // For the strcpy() function
using std::cin;
using std::cout;
using std::endl;
void eatspaces(char* str); // Function to eliminate blanks
double expr(char* str); // Function evaluating an expression
double term(char* str, int& index); // Function analyzing a term
double number(char* str, int& index); // Function to recognize a number
char* extract(char* str, int& index); // Function to extract a substring
const int MAX = 80; // Maximum expression length,
// including '\0'
int main()
{
char buffer[MAX] = {0}; // Input area for expression to be evaluated
cout