Skip to content
Dr Jack HW Helper
Home
Browse
About
Contact
Academic Integrity
T
Academic Integrity:
tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.
Home
Browse
W
Write a small program that will check for balancing symbols in C++. Look for: /*
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
Related Questions
Write a six- to eight-page paper identifying and describing your personal action
Question #307408
Write a sixth game program using the random number generator to generate a five-
Question #3546185
Write a sixth game program using the random number generator to generate a five-
Question #3559882
Write a slope-intercept equation for a line passing through the point (3, - 2) t
Question #3113033
Write a small C program called tinyshell that behaves much like a shell; but you
Question #3794547
Write a small C program newcat , which performs exactly as oldcat (shown below)
Question #3793149
Write a small C program newcat , which performs exactly as oldcat (shown below)
Question #3799587
Write a small C program that loops reading a line from standard input and checks
Question #3789707
Navigate
Browse (All)
Browse W
Subjects
Previous
Write a small program that fills an array of doubles with user input, prints the
Next
Write a small program to print the sum of the integers between Mand N, inclusive