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

Write a small program that will check for balancing symbols in C++. Look for: /*

ID: 3622450 • Letter: W

Question

Write a small program that will check for balancing symbols in C++. Look for:


/* */


( )


[ ]


{ }

Explanation / Answer

#include #include #include enum { EMPTY = -1 }; using namespace std; class stack { public: stack() { max_len=1000; s = new int[max_len]; top=EMPTY;; } ~stack() { delete []s; } void reset() { top = EMPTY; } void push(int c) { s[++top] = c; } int pop() { return s[top--]; } int top_of()const { return s[top]; } bool empty()const { return top == EMPTY;} bool full()const { return top == max_len - 1;} private: int *s; int max_len; int top; }; int main() { char ch; stack s; int i,j; int card[52],num,print; char file[100],output; ifstream ifile; bool cond1=false,cond2=false;; coutfile; ifile.open(file); //open a file if (ifile.is_open()) { while(!ifile.eof()){ ifile>>output; if(output =='/') { cond1=true; ifile>>output; } else if(output=='*') { cond1=false; cond2=true; ifile>>output; } else { cond1=cond2=false; } if(ifile.eof()) break; if(!s.full()) { if(output=='(' || output =='{' || output =='[' ||(cond1&& output=='*')) s.push(output); } if(output==')' || output =='}' || output ==']'||(cond2==true&& output=='/')) { ch = s.pop(); if((output == ')' && ch != '(')||(output == '{'&& ch != '}')||(output == ']' && ch != '[')||(output=='/' && ch!='*') ) { cout
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