Starting Out with C++ from Control Structures through Objects Brief, Student Value Edition (8th Edition)
Question
Book Icon
Chapter 18, Problem 14PC
Program Plan Intro

Balanced Parentheses

Program Plan:

  • Include required header files
  • Declare function prototype
  • Inside “main ()” function,
    • Declare a variable “strng”.
    • Get a string from the user.
    • Check if the Boolean function “is_Balanced ()” returns true.
      • If the condition is true then the string has balanced parentheses.
      •  If the condition is not true then the string does not have balanced parentheses.
  • In “is_Balanced ()” function,
    • Declare a Boolean variable “status”.
    • Create an object for stack.
    • Use for loop to step through each character in a string.
      • Use Switch…Case structure check the character has set of parentheses or not.
        • If left parenthesis is detected,
          • Push it into the stack using the function “push ()”.
        • If right parenthesis is detected,
          • Check if the stack is empty using the function “empty()”.
            • If the stack is empty then assign “false”
            • If the stack is not empty then assign “true”
    • Check if the stack is empty and assign “true”. Else, assign “false”.
    • Return the variable “status”.

Blurred answer
Students have asked these similar questions
. Balanced ParenthesesA string of characters has balanced parentheses if each right parenthesis occurringin the string is matched with a preceding left parenthesis, in the same way that eachright brace in a C++ program is matched with a preceding left brace. Write a programthat uses a stack to determine whether a string entered at the keyboard has balancedparentheses.
In C programming language please  Write a program that uses a stack to check if a given string is a palindrome or not. A palindrome is a word, phrase, number, or other sequence of characters that reads the same backward as forward. Your program should use a stack to reverse the characters of the given string, and then compare the reversed string with the original string to determine if it is a palindrome or not. Here are some additional requirements for your program:  Your program should prompt the user to enter a string and read it from the standard input.  Your program should define a stack data structure with push() and pop() functions to store and retrieve characters.  Your program should use the stack to reverse the characters of the input string and store the reversed string in a separate variable.  Your program should then compare the reversed string with the original string to determine if it is a palindrome.  Your program should output whether or not the input string is a…
C++ programming Write a function that uses a stack to test whether a given string (as a character array) is a palindrome. Exercise 14 asked you to write an algorithm for such a function. Although this solution can be solved with simple looping (and it is with the isPlaindromIterative function) - we want to demonstrate an understanding of stack structures to check for a palindrome. Input accept a string (as a character array) add characters to the stack Processing push pop peek (top) Output use stack methods to check for palindromes Efficient Correct

Chapter 18 Solutions

Starting Out with C++ from Control Structures through Objects Brief, Student Value Edition (8th Edition)

Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning