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
WAP c# program creates a string, s1, which deliberately leaves space for a name, much like you’d do with a letter you plan to run through a mail merge. We add two to the position where we find the comma to make sure there is a space between the comma and the name.
Edef reverse_sentence (s: str) -> str: Given a sentence , we define a word within to be a continuous sequence of characters in that starts with a capital letter and ends before the next capital letter in the string or at the end of the string, whichever comes first. A word can include a mixture of punctuation and spaces. This means that in the string 'ATest string!', there are in fact only two words: 'A' and 'Test string!'. Again, keep in mind that words start with a capital letter and continue until the next capital letter or the end of the string, which is why we consider 'Test string!' as one word. This function will reverse each word found in the string, and return a new string with the reversed words, as illustrated in the doctest below. >>> reverse_sentence('ATest string!') 'A!gnirts tseT' return
Data structure/ C language /  Graph /  Dijkstra’s algorithm implement a solution of a very common issue: how to get from one town to another using the shortest route.* design a solution that will let you find the shortest paths between two input points in a graph, representing cities and towns, using Dijkstra’s algorithm. Your program should allow the user to enter the input file containing information of roads connecting cities/towns. The program should then construct a graph based on the information provided from the file. The user should then be able to enter pairs of cities/towns and the algorithm should compute the shortest path between the two cities/towns entered.Attached a file containing a list of cities/towns with the following data:Field 1: Vertex ID of the 1st end of the segmentField 2: Vertex ID of the 2nd of the segmentField 3: Name of the townField 4: Distance in Kilometer Please note that all roads are two-ways. Meaning, a record may represent both the roads from…

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