Starting Out With C++: Early Objects, Student Value Edition (9th Edition)
Starting Out With C++: Early Objects, Student Value Edition (9th Edition)
9th Edition
ISBN: 9780134379319
Author: Tony Gaddis, Judy Walters, Godfrey Muganda
Publisher: PEARSON
bartleby

Concept explainers

Question
Book Icon
Chapter 18, Problem 11PC
Program Plan Intro

Balanced Multiple Delimiters

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 delimiters.
      • If the condition is not true then the string does not have balanced delimiters.
  • Inside “is_Balanced ()” function,
    • Declare a Boolean variable “status”.
    • Declare a character variable “expected”
    • Create an object for stack.
    • Loop each character.
      • Switch to the character.
        • If left parenthesis is detected,
          • Push it into the stack using the function “push ()”.
        • If left braces is detected,
          • Push it into the stack using the function “push ()”.
        • If left bracket is detected,
          • Push it into the stack using the function “push ()”.
        • If right parenthesis or right bracket or right braces is detected,
          • Get the top element from the stack and store it in a variable “expected”
        • Check if the expected character is not equal to “str[k]”.
          • Assign “false” if the condition is true.
          • Else, pop the element
    • Check if the stack is empty and assign “true”. Else, assign “false”.
    • Return the variable “status”.

Blurred answer
Students have asked these similar questions
Two-dimensional list tictactoe represents a 3x3 tic-tac-toe game board read from input. List tictactoe contains three lists, each representing a row. Each list has three elements representing the three columns on the board. Each element in the tic-tac-toe game board is 'x', 'o', or '-'. If all the elements at column index 0 are 'o', output 'A win at column 0.' Otherwise, output 'No win at column 0.'
City and State.   Extract the city name and state from strings like “Utica, NY” and “Los Angeles, CA”. Assume the state is always the last two characters in the string, the city name has at least one character, there is a comma following the city name, and a single space after the comma. Use the split method to separate the city name from the state (Notice the city name will still have a comma at the end). The following attachement is a sample execution:
def convert_data(data: List[list]) -> None:    """Convert each string in data to an int if and only if it represents a    whole number, and a float if and only if it represents a number that is not    a whole number.     >>> d = [['abc', '123', '45.6', 'car', 'Bike']]    >>> convert_data(d)    >>> d    [['abc', 123, 45.6, 'car', 'Bike']]    >>> d = [['ab2'], ['-123'], ['BIKES', '3.2'], ['3.0', '+4', '-5.0']]    >>> convert_data(d)    >>> d    [['ab2'], [-123], ['BIKES', 3.2], [3, 4, -5]]    """     an easier way to do this for begniners
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
  • Text book image
    Systems Architecture
    Computer Science
    ISBN:9781305080195
    Author:Stephen D. Burd
    Publisher:Cengage Learning
Text book image
Systems Architecture
Computer Science
ISBN:9781305080195
Author:Stephen D. Burd
Publisher:Cengage Learning