⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 operator.cpp

📁 利用c++自带函数尽可能完整的实现简单算术表达式求值.
💻 CPP
字号:
#include   <stdio.h>   
  #include   <ctype.h>   
  #include   <stdlib.H>   
  #include   <string.h>   
    
  void   Ready(char   *   str)   
  {   
  scanf("%s",   &str[1]);   
  str[0]   =   '(';   
  str[strlen(str)]   =   ')';   
  }   
    
  double   CalStr(char   *   str)   
  {   
  double   result;   
  int   flag   =   0;   
  if   (   isdigit(*str))   
  {   
  result   =   atol(str);   
  while   (   isdigit(*str))   *(str++)   =   '#';   
  }   
  else   
  {   
  if   (   *str   ==   '-')   result   =   -CalStr(str+1);   
  else   result   =   CalStr(str+1);   
  if   (   *str   ==   '('   )   flag   =   1;   
  *str   =   '#';   
  while   (   *str   ==   '#'   )   str++;   
  while   (   *str   !=   ')')   
  {   
  switch(*str)   
  {   
  case   '*':   result   *=   CalStr(str+1);   break;   
  case   '/':   result   /=   CalStr(str+1);   break;   
  default:   result   +=   CalStr(str);   break;   
  }   
  *str   =   '#';   
  while   (   *str   ==   '#')   str++;   
  }   
  if   (   flag   ==   1   )   *str   =   '#';   
  }   
  return   result;   
  }   
    
  void   main()   
  {   
  char   str[100];   
  Ready(str);   
  printf("\nthe   result   is   %lf\n",   CalStr(str));   
  }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -