Sponsored Links

Results 1 to 1 of 1

Thread: CS301 Data Structure VU Current Assignment No. 1 semester Fall November 2012

  1. #1
    Senior Member
    Join Date
    Oct 2012

    CS301 Data Structure VU Current Assignment No. 1 semester Fall November 2012

    Sponsored Links

    CS301 Data Structure VU Current Assignment No. 1 semester Fall November 2012

    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.


    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:
    ( ), { }, [ ]

    Sponsored Links

    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 Attached Files

  2. Sponsored Links

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 1
    Last Post: 07-24-2014, 05:41 PM
  2. CS301 Data Structures Assignment No 2 Fall Semester 5th November 2012
    By Vuhelper in forum Assignments & Solutions
    Replies: 0
    Last Post: 11-05-2012, 05:09 PM
  3. Replies: 9
    Last Post: 11-19-2011, 05:51 AM
  4. Replies: 7
    Last Post: 11-02-2011, 04:32 AM
  5. Replies: 8
    Last Post: 11-07-2010, 06:21 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
-: Vuhelp Disclaimer :-
None of the files shown here are hosted or transmitted by this server. The links are provided solely by this site's users. The administrator's or staff of Vuhelp.net cannot be held responsible for what its users post, or any other actions of its users. You may not use this site to distribute or download any material when you do not have the legal rights to do so. It is your own responsibility to adhere to these terms. If you have any doubts about legality of content or you have any suspicions, feel free to contact us.
Online Education | JhelumSoft