Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

You will create a text file that will consist of expression strings, one express

ID: 3807390 • Letter: Y

Question

You will create a text file that will consist of expression strings, one expression string per line. Assume that the file contents are all valid infix expressions follow the rules established in this assignment. Do not have the program check for arithmetical syntax errors that may exist in the file.

Use the C++ streams capability to read the file contents into a string based stream. Your program should read a line that has a valid expression into an infix string that will display the inputted infix string, process the infix string to a postfix string using a shunting yard algorithm and display the postfix string. The code should then go back and read another infix expression line until the whole file has been read and processed.

Populate the expression file with valid expressions using the rules in this document. You need to show that you are testing valid expressions for a variety of expressions that covers all operators, operator precedence and use parentheses.

You will be graded on the expressions you create to thoroughly test your program.

The program must use: Application class named: ShuntingYardClass Stack template class named: OperatorStackClass Map template class named: OperatorMapClass Use a template map class for precedence determination. Use a template stack class for the shunting yard.

The program must be modular, well structured, well organized and follow the best programming practices document

Explanation / Answer

#include #include #include int top = -1; char stack[100]; // function prototypes void push(char); void pop(); void find_top(); void main() { int i; char a[100]; printf("enter expression "); scanf("%s", &a); for (i = 0; a[i] != '';i++) { if (a[i] == '(') { push(a[i]); } else if (a[i] == ')') { pop(); } } find_top(); } // to push elements in stack void push(char a) { stack[top] = a; top++; } // to pop elements from stack void pop() { if (top == -1) { printf("expression is invalid "); exit(0); } else { top--; } } // to find top element of stack void find_top() { if (top == -1) printf(" expression is valid "); else printf(" expression is invalid "); }
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote