4-)Below is a program written in order to perform a task, trace the program and providecommentsfor 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;}
#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;}
#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;}
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;}
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();
switch (c)
case '+': n = a + b;
break;
case '*': n = a * b;
case '/': n = a / b;
case '-': n = a - b;
num_stack.push(n);
else
num_stack.push(atof(p));
p = strtok(NULL, " ");
cout < "the="" answer="" is:="" "="">< num_stack.top()=""><>
return 0;
Already registered? Login
Not Account? Sign up
Enter your email address to reset your password
Back to Login? Click here