free geoip

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
CS301 Data Structure VU Current Assignment No. 1 semester Fall November 2012
VU Help • House Banner VU Help Virtual University Students - Assignments, Solved Papers, GDB & Exam Help Student Help Forum • Collaborative • Free Support
#1
CS301 Data Structure VU Current Assignment No. 1 [size=12]semester Fall November 2012[/SIZE]


In any programming language, when a program containing any expression/string is executed, a language translator such as compiler checks whether the brackets in the expression/string are properly balanced or not. Brackets are properly balanced if each opening bracket has its corresponding closing bracket. Compiler executes the program successfully if expression/string contains properly balanced brackets but generates syntax error in case of unbalanced pair of brackets.
For example, expression/string: [{(A+B)*C}/D], (a+345), and “(Welcome)” contains properly balanced pairs of brackets, but the expression: [{(A+B)*10}/D does not.

Write a program in C++ that prompts a user to enter an expression/string containing brackets. Pass this expression to a function which checks it for balanced/unbalanced pair of brackets. Then, print “Balanced” if this expression has balanced pair of brackets, and print “Unbalanced” otherwise.

Hint:

1. You have to use stack to keep record of left brackets (i.e. opening brackets).

Solution Guidelines:

1. Create a class named “bracket_checker” that should contain following inline functions:
• Constructor( ): To initialize “bracket_cheker” class data members.
• Isempty( ): To check whether a stack is empty or not.
• Push( ) // To push any opening bracket onto the stack
• Pop( ) // To pop bracket from top whenever a closing bracket is found
• Checkbrackets( ) // To check whether brackets are balanced or not

2. Your program should be able to check following pair of brackets:
( ), { }, [ ]

3. You have to check the following:

1. (a). There should be no mismatch of brackets e.g. ‘)’ against ‘{‘
(b). Each opening bracket should contain its corresponding matching closing bracket. E.g. ‘)’ against ‘(‘
2. Expression should not contain only opening brackets
3. Expression should not contain only closing brackets
4. Number of left (opening) and right (closing) brackets should be equal

4. In main() function:
(a). Create an object test of type bracket_checker.
(b). Prompt the user to enter an expression/string and call Check_brackets() function to check whether it is balanced or not. Expression/string entered by user should be passed to Check_brackets() function as parameter.

Note: You are required to test at least two different expressions/strings.

Sample Input:

Following are two different sample input expressions:

• [{((5*3)+(2+5)*(3/2))}/5]

• [{(A*(A*3))+((B+5)*(C-D))*((3/2)-5)}]]

Sample output:
Please open the separate file attached with assignment file.

Note: Your solution can be checked for any expression. So, your program should be able to generate correct output for every expression.




Attached Files
.docx   Cs301-Nov-2012.docx (Size: 11.28 KB / Downloads: 180)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  VU Fall 2026 Assignments: How to Write Solutions That Get Full Marks (Complete Guide) admin 0 2 8 hours ago
Last Post: admin
  SEO in Simple Words: How a VU Student Can Write a Clearer Assignment or Blog Post admin 0 24 11-01-2026, 05:11 AM
Last Post: admin
  Cs403 Assignment 3 Helping material May 8,2010 viki 1 5,241 04-28-2020, 03:19 PM
Last Post: ClaireBeauc
  cs301 assignment no 3 Solution 20 January 2016 Vuhelper 0 11,117 01-20-2016, 03:32 PM
Last Post: Vuhelper
  CS201 Assignment vo 3 Solution 20th January 2016 Vuhelper 2 2,633 01-20-2016, 03:28 PM
Last Post: Vuhelper
  CS101 Assignment no 3 Solution 20th January 2016 Vuhelper 0 2,314 01-20-2016, 03:25 PM
Last Post: Vuhelper
  SOC101 INTRODUCTION TO SOCIOLOGY assignment no 3 Solution 20 January 2016 Vuhelper 0 1,902 01-20-2016, 03:19 PM
Last Post: Vuhelper
  CS402 Assignment No 4 Solution & Discussion Xpert 0 2,133 08-01-2015, 02:33 AM
Last Post: Xpert
  cs101 Assignment No. 1 Solution 21 may spring 2015 semester Xpert 0 2,943 05-21-2015, 12:41 AM
Last Post: Xpert
  Assignment solution eng 301 due date 20 may 2015 rumesa khan 3 4,563 05-20-2015, 01:34 AM
Last Post: Xpert

Forum Jump:


Users browsing this thread: 1 Guest(s)
VU Help • House Banner VU Help Virtual University Students - Assignments, Solved Papers, GDB & Exam Help Student Help Forum • Collaborative • Free Support