4-) Below is a program written in order to perform a task, trace the program and provide comments for the code. In a few sentences, describe what does the program do? and show the result of the...



4-)
Below is a program written in order to perform a task, trace the program and provide
comments
for the code.
In a few sentences, describe what does the program do? and show the result of the execution:











#include


#include


#include


using namespace std;


#define maxchars 100//



int main()


{


      char input_str[maxchars+1], *p;


      stack num_stack;


      int c;


      double a, b, n;



      cout < "enter="" string:="">


            cin.getline(input_str, maxchars);


      p = strtok(input_str, " ");


      while (p)


      {


            c = p[0];


            if (c == '+' || c == '*' || c == '/' || c == '-')


            {


                  if (num_stack.size() <>


                  {


                        cout < "error:="" too="" many="" ops."=""><>


                        system("pause");


                        return -1;


                  }


            b = num_stack.top();


            num_stack.pop();


            a = num_stack.top();


            num_stack.pop();


            switch (c)


            {


            case '+': n = a + b;


                  break;


            case '*': n = a * b;


                  break;


            case '/': n = a / b;


                  break;


            case '-': n = a - b;


                  break;


            }


            num_stack.push(n);


      }


      else


      {


            num_stack.push(atof(p));



      }


      p = strtok(NULL, " ");


}


cout < "the="" answer="" is:="" "="">< num_stack.top()=""><>


      system("pause");


      return 0;


}





Jun 07, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here