Starting Out with C++ from Control Structures to Objects (8th Edition)
Starting Out with C++ from Control Structures to Objects (8th Edition)
8th Edition
ISBN: 9780133769395
Author: Tony Gaddis
Publisher: PEARSON
bartleby

Concept explainers

Question
Book Icon
Chapter 18, Problem 15PC
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
T/F Suffix array can be created in O(nlogn) time.
flip_matrix(mat:list)->list You will be given a single parameter a 2D list (A list with lists within it) this will look like a 2D matrix when printed out, see examples below. Your job is to flip the matrix on its horizontal axis. In other words, flip the matrix horizontally so that the bottom is at top and the top is at the bottom. Return the flipped matrix. To print the matrix to the console:  print('\n'.join([''.join(['{:4}'.format(item) for item in row]) for row in mat])) Example: Matrix:
W R I T X
H D R L G
L K F M V
G I S T C
W N M N F
Expected:
W N M N F
G I S T C
L K F M V
H D R L G
W R I T X Matrix:
L C
S P
Expected:
S P
L C Matrix:
A D J
A Q H
J C I
Expected:
J C I
A Q H
A D J
Language is C++

Chapter 18 Solutions

Starting Out with C++ from Control Structures to Objects (8th Edition)

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
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage