Starting Out with C++ from Control Structures to Objects (8th Edition)
8th Edition
ISBN: 9780133769395
Author: Tony Gaddis
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
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
- If left parenthesis is detected,
- Switch to the character.
- Check if the stack is empty and assign “true”. Else, assign “false”.
- Return the variable “status”.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents 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)
Ch. 18.3 - Describe what LIFO means.Ch. 18.3 - What is the difference between static and dynamic...Ch. 18.3 - What are the two primary stack operations?...Ch. 18.3 - What STL types does the STL stack container adapt?Ch. 18 - Prob. 1RQECh. 18 - Prob. 2RQECh. 18 - What is the difference between a static stack and...Ch. 18 - Prob. 4RQECh. 18 - Prob. 5RQECh. 18 - The STL stack is considered a container adapter....
Ch. 18 - What types may the STL stack be based on? By...Ch. 18 - Prob. 8RQECh. 18 - Prob. 9RQECh. 18 - Prob. 10RQECh. 18 - Prob. 11RQECh. 18 - Prob. 12RQECh. 18 - Prob. 13RQECh. 18 - Prob. 14RQECh. 18 - Prob. 15RQECh. 18 - Prob. 16RQECh. 18 - The STL stack container is an adapter for the...Ch. 18 - Prob. 18RQECh. 18 - Prob. 19RQECh. 18 - Prob. 20RQECh. 18 - Prob. 21RQECh. 18 - Prob. 22RQECh. 18 - Prob. 23RQECh. 18 - Prob. 24RQECh. 18 - Prob. 25RQECh. 18 - Prob. 26RQECh. 18 - Write two different code segments that may be used...Ch. 18 - Prob. 28RQECh. 18 - Prob. 29RQECh. 18 - Prob. 30RQECh. 18 - Prob. 31RQECh. 18 - Prob. 32RQECh. 18 - Prob. 1PCCh. 18 - Prob. 2PCCh. 18 - Prob. 3PCCh. 18 - Prob. 4PCCh. 18 - Prob. 5PCCh. 18 - Dynamic String Stack Design a class that stores...Ch. 18 - Prob. 7PCCh. 18 - Prob. 8PCCh. 18 - Prob. 9PCCh. 18 - Prob. 10PCCh. 18 - Prob. 11PCCh. 18 - Inventory Bin Stack Design an inventory class that...Ch. 18 - Prob. 13PCCh. 18 - Prob. 14PCCh. 18 - Prob. 15PC
Knowledge Booster
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
- T/F Suffix array can be created in O(nlogn) time.arrow_forwardflip_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 Jarrow_forwardQ: Write a program that reads from the user a string matrix with 4x4 dimensions, the program has to count how many a specific name that is given by the user is repeated inside the matrix.arrow_forward
- javascript Define a function, myIncludes, that accepts two parameters: an array and a searchValue. myIncludes should return true if the searchValue is an element in the array. Otherwise, myIncludes should return false. example myIncludes([10, 20, 30], 20); // => true myIncludes(['apples', 'bananas', 'citrus'], 'pears'); // => falsearrow_forwarddef swap_text(text): Backstory: Luffy wants to organize a surprise party for his friend Zoro and he wants to send a message to his friends, but he wants to encrypt the message so that Zoro cannot easily read it. The message is encrypted by exchanging pairs of characters. Description: This function gets a text (string) and creates a new text by swapping each pair of characters, and returns a string with the modified text. For example, suppose the text has 6 characters, then it swaps the first with the second, the third with the fourth and the fifth with the sixth character. Parameters: text is a string (its length could be 0)Return value: A string that is generated by swapping pairs of characters. Note that if the Examples: swap_text ("hello") swap_text ("Party for Zoro!") swap_text ("") def which_day(numbers): → 'ehllo'→ 'aPtr yof roZor!' → '' length of the text is odd, the last character remains in the same position.arrow_forwardBy pythonarrow_forward
- Data structures find_color(colors:set, values:list) -> list The function will have two parameters. The first parameter is a set of strings known as Colors. A second parameter is a list of tuple-2 known as Values. Colors will contain a set of randomly selected colors. Values will contain a list of tuples of size 2. Each tuple will contain color (str) and a number (int). The function should look at each tuple in Values. For each tuple, add the number (the second value in the tuple) to a list of numbers if the color in the tuple (the first value in the tuple) is in Colors. In other words, find all tuples that have a color in the Colors and add the tuples numbers to a list. Finally, the function should return the list of numbers collected in the order they are found in the values list. Example: Colors: {'black', 'pink', 'yellow'} values: [('green', 100), ('yellow', 13), ('red', 6)] Expected: [13] Colors: {'yellow'} values: [('black', 54), ('pink', 5)] Expected: [] Colors: {'black',…arrow_forwardC++arrow_forwardData structure & Algorithum. Java Program Write code that accomplishes the following tasks. Consider two bags that can hold strings. One bag is named letters and contain seeral one-letter strings. The other bag is empty and is namedvowels. One at a time removed a string from letters. If the string contain a vowel place it into bag vowels, otherwise, discard the string. After you have checked all of the strings in letters, report the number of vowels and the number of times each vowels appears in the bag.arrow_forward
- Words with given shape def words_with_given_shape(words, shape): The shape of the given word of length n is a list of n - 1 integers, each one either -1, 0 or +1 to indicate whether the next letter following the letter in that position comes later (+1), is the same (0) or comes earlier (-1) in the alphabetical order of English letters. For example, the shape of the word 'hello' is [-1, +1, 0, +1], whereas the shape of 'world' is [-1, +1, -1, -1]. Find and return a list of all words that have that particular shape, listed in alphabetical order. Note that your function, same as all the other functions speci0ied in this document that operate on lists of words, should not itself try to read the wordlist 0ile words_sorted.txt, even when Python makes this possible with just a couple of lines of code. The tester script already reads in the entire wordlist and builds the list of words from there. Your function should use this given list of words without even caring which particular 0ile it…arrow_forwardWords with given shape def words_with_given_shape(words, shape): The shape of the given word of length n is a list of n - 1 integers, each one either -1, 0 or +1 to indicate whether the next letter following the letter in that position comes later (+1), is the same (0) or comes earlier (-1) in the alphabetical order of English letters. For example, the shape of the word 'hello' is [-1, +1, 0, +1], whereas the shape of 'world' is [-1, +1, -1, -1]. Find and return a list of all words that have that particular shape, listed in alphabetical order. Note that your function, same as all the other functions specified in this document that operate on lists of words, should not itself try to read the wordlist file words_sorted.txt, even when Python makes this possible with just a couple of lines of code. The tester script already reads in the entire wordlist and builds the list of words from there. Your function should use this given list of words without even caring which particular file it…arrow_forwardIn Python Asap plsarrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage