实现带有括号的四则运算功能要求:输入一个表达式,计算出其正确结果.例如:输入:123+213-67*34+345/23*45*(34+34-345+245+567)回车计算结果为:359183
来源:学生作业帮助网 编辑:作业帮 时间:2024/08/01 05:37:55
![实现带有括号的四则运算功能要求:输入一个表达式,计算出其正确结果.例如:输入:123+213-67*34+345/23*45*(34+34-345+245+567)回车计算结果为:359183](/uploads/image/z/11455194-66-4.jpg?t=%E5%AE%9E%E7%8E%B0%E5%B8%A6%E6%9C%89%E6%8B%AC%E5%8F%B7%E7%9A%84%E5%9B%9B%E5%88%99%E8%BF%90%E7%AE%97%E5%8A%9F%E8%83%BD%E8%A6%81%E6%B1%82%EF%BC%9A%E8%BE%93%E5%85%A5%E4%B8%80%E4%B8%AA%E8%A1%A8%E8%BE%BE%E5%BC%8F%2C%E8%AE%A1%E7%AE%97%E5%87%BA%E5%85%B6%E6%AD%A3%E7%A1%AE%E7%BB%93%E6%9E%9C.%E4%BE%8B%E5%A6%82%EF%BC%9A%E8%BE%93%E5%85%A5%EF%BC%9A123%2B213-67%2A34%2B345%2F23%2A45%2A%EF%BC%8834%2B34-345%2B245%2B567%EF%BC%89%E5%9B%9E%E8%BD%A6%E8%AE%A1%E7%AE%97%E7%BB%93%E6%9E%9C%E4%B8%BA%EF%BC%9A359183)
实现带有括号的四则运算功能要求:输入一个表达式,计算出其正确结果.例如:输入:123+213-67*34+345/23*45*(34+34-345+245+567)回车计算结果为:359183
实现带有括号的四则运算
功能要求:输入一个表达式,计算出其正确结果.
例如:输入:123+213-67*34+345/23*45*(34+34-345+245+567)回车
计算结果为:359183
实现带有括号的四则运算功能要求:输入一个表达式,计算出其正确结果.例如:输入: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