Question: Write a program that decides whether a file contains balanced curly braces, parentheses, square brackets, and angled brackets. Input the file name, open it, and

Write a program that decides whether a file contains balanced curly braces, parentheses, square brackets, and angled brackets. Input the file name, open it, and read one character at a time until end-of-file. If the file is balanced, your program should output "Balanced". If the file is not balanced, your program should output "Not Balanced". For example, the following files are balanced:

[()]{([])} 
This is  {test} file and [your] program should [({o}ut)p{u}[t] ][] Balanced 

#include  using namespace std; main() { int a[100]; a[20] = ((13 / 2) + a[5]) / 2; cout > a[20]; }

And the following files are not balanced:

This is { ( not ) a  file
neither is this  ] ( ) [ 
{ ( not balanced } )

Use a stack of characters.

stack brackets; 
When an open bracket is read, it's pushed on stack. When a close bracket is read and its corresponding open bracket is on top of stack, the open bracket is popped.

Hand in a printout of your program and typescript of sample runs for each of the above input files.

 Write a program that decides whether a file contains balanced curly

Write a program that decides whether a file contains balanced curly braces, parentheses, square brackets, and angled brackets. Input the file name, open it, and read one character at a time until end of-file. If the file is balanced, your program should output "Balanced". If the file is not balanced, your program should output "Not Balanced". For example, the following files are balanced: This is (test) file and [your] program should [(ojut)piujt] 1 Balanced include using namespace std; main() int a[100]: al20)-((132) a[5) 2; cout > a[ 20] And the following files are not balanced: This is not) a balanced> file neither is this not balanced j Use a stack of characters stackcchar brackets; When an open bracket is read, it's pushed on stack. When a close bracket is read and its corresponding open bracket is on top of stack, the open bracket is popped Hand in a printout of your program and typescript of sample runs for each of the above input files

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!