Menu

(Solved) : Given Text File Program Determine Parentheses Braces Square Brackets Match Nested Appropri Q28959836 . . .

Given a text file, your program will determine if all theparentheses, braces, and square brackets match, and are nestedappropriately. Your program should work for mathematical formulasand most computer programs.

Your program should read in the characters from the file, butignore all characters except for the following: { } ( ) [ ]

Your program should use the IntStack declaration(IntStack.h), which will be available fromTracs).

The general algorithm is to use a stack to store the openingunmatched brackets. When a closing bracket is encountered, check itagainst the one on top of the stack– make sure it matches, and popit off. When you are finished there should be no unmatched bracketsleft on the stack.

Input/Output:

Your driver program must prompt the user to enter a filename. Itshould then try to open the file and then check it to ensure thebrackets all match appropriately. If they all match, the programshould output a message saying so. If not, the program shouldoutput an appropriate error message (there are three possible errormessages corresponding to three types of errors shown asfollows).

There are three types of errors that can happen (and with anykind of bracket):

missing } : if you reach the end of the file, and there is anopening { that was never matched, like: int main () {x[size]=10;

expected } but found ) : this is a wrong closing bracket, like:{x[i]=10;)…

unmatched } : this occurs if there is a closing bracket but notan opening bracket (not even one of the wrong kind), like: int main() { x[i]=10; } }…

NOTES:

• This program must be done in a Linux or Unix environment,using a command line compiler like g++. Do not use codeblocks,eclipse, or Xcode to compile.

• As soon as your driver encounters an error, your programshould stop and print out the appropriate error message. Do NOT tryto keep going and find more errors!

• The stack is an int stack but you will probably want to putcharacters on the stack. You can push a character directly on theint stack (it will automatically be converted to an int). When youpop I recommend popping into a char variable first (this willautomatically convert the int back into a character).

• It might be easier to store the expected closing character onthe stack when an opening bracket is encountered. This simplifiesthe matching when a closing bracket is encountered.

• Beware of stack underflow! Do NOT try to pop an empty stack!If you get an error message like this when you run your program:Assertion failed: (!isEmpty()) then you are popping an empty stack:your program should prevent this and output its own appropriateerror message instead. • Follow the style guidelines from theTracs. Logistics: For this assignment you need to submit two files:IntStack.cpp and your driver file. Please zip these into one file,assign6_xxxxxx.zip (where xxxxx is your NetID). Then submit the zipfile

Pls use this header file

// Specification file for the IntStack class// Adapted from Gaddis source codeclass IntStack{private: struct Node{ int data; Node* next; }; Node* head; //ptr to top public: // Constructor IntStack(); //Destructor ~IntStack(); // Stack operations void push(int); int pop(); bool isFull(); bool isEmpty();};

Please use structure in the class as shown in the headerfile

Expert Answer


Answer to Given Text File Program Determine Parentheses Braces Square Brackets Match Nested Appropri Q28959836 . . .

OR