Question
I'm struggling trying to convert this program into a template using C++. I have the code, but getting syntax errors. Can anyone help? I'd really
I'm struggling trying to convert this program into a template using C++. I have the code, but getting syntax errors. Can anyone help? I'd really appreciate it.
#include
template
}; template
char top() { return myStk.getElement(); }
bool full() { return (myStk.size() == myStk.get_CAP()); }
bool empty() { return myStk.empty(); }
int size() { return myStk.size(); } };
void print_result(bool x) { if (x) { outfile << endl << "The string is matched." << endl << endl; } else { outfile << endl << "The string is mismatched." << endl << endl; } }
void handle(char x, bool& match, stack& stk) { outfile << x; if ((x == '(') || (x == '[') || (x == '{') || (x == '<')) { stk.push(x); } else if ((x == ')') || (x == ']') || (x == '}') || (x == '>')) { if (!(stk.top())) { match = false; } else if ((stk.top() == '(') && (x == ')')) { stk.pop(); } else if ((stk.top() == '[') && (x == ']')) { stk.pop(); } else if ((stk.top() == '{') && (x == '}')) { stk.pop(); } else if ((stk.top() == '<') && (x == '>')) { stk.pop(); } else { match = false; } } }
int main() { outfile.open("Results.txt"); test.open("Brackets.txt"); data1.open("LispClassData.txt"); stack3.open("Stack3.txt");
stack Stack1, Stack2, Stack3, Stack4; stack
while (test >> x) // File 1 { handle(x, match, Stack1); } if ((Stack1.top())) { match = false; } print_result(match);
match = true;
while (data1 >> x) // File 2 { handle(x, match, Stack2); } if ((Stack2.top())) { match = false; } print_result(match);
match = true;
while (stack3 >> x) // File 3 { handle(x, match, Stack4); } if ((Stack4.top())) { match = false; } print_result(match);
stack3.close(); data2.close(); data1.close(); test.close(); outfile.close(); system("Pause"); return EXIT_SUCCESS; }
Here is a test file called brackets.txt:
( ) [ ] ( ) { } [ { ( ) } ] < > <<< >>> [ [ ) ) { ( ) [ ( ) ] }
The other two files I have will work if this one does. Once again, thank you.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started