Make a program that prompts the user to enter the value of A,B,C,D, and E. Then the user must enter and Arithmetic Notation using InFix, Then prints the Result.
Must use Stack..
If you read a variable, push its value onto the stack.
If you read an operator, pop the top two values off the stack, perform the operation, and push the result onto the stack.
Repeat until end of input.
At end of input, there should be only one value on the stack, and it will be the answer.
Can you guys give me a sample program about implementing a postfix notation?
I know how to Pop and Push, but my question is. as you can see in the program, the Arithmetic Notation is in Char, now like example the program reads "a" i want it to push the value the user gave on and not the character..
And Question will it automatically add the variables? when an operator is read?
#include <iostream>
usingnamespace std;
int main () {
int values[5];
for(char c='A'; c<='E'; c++) { //store the values in the array
cin >> values[c-'A'];
}
//read the expression here...
//now loop for each character in the expression...
//if for example you've read D then push values['D'-'A']
//sample
cout << endl << values['D'-'A']; //showing the value of D
return 0;
}