Problem Solving with C++ (10th Edition)
10th Edition
ISBN: 9780134448282
Author: Walter Savitch, Kenrick Mock
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 8, Problem 6P
Program Plan Intro
LookupName function using Vector
Program Plan:
- Include the appropriate headers into program.
- Declare the “lookupName()” function.
- Define the function “lookupName()” with three parameters.
- The first parameter “targetName” is to identify the name in the array.
- The second parameter “names” is to store names into vector.
- The third parameter “numbers” is to store numbers into vector.
- Declare and define the variables with its initialization.
- Using “for” loop, check the “targetName” is available in array or not.
- If the condition is true, assign the numbers into variable.
- Assign the vector values to variable.
- Return the phone number for the corresponding name.
- Define the “main()” function.
- Initialize the
vectors for names and phone numbers. - Add the names and phone numbers to the vector using the function “push_back()”.
- Using “do-while” loop, prompt the user for name.
- Call the “lookupName()” function with appropriate arguments.
- Using “if-else” condition, check the resultant number is in array or not.
- If the condition is true, print the result.
- Otherwise, print “Name not found” statement.
- Get the sentinel value from user to check in “while” loop.
- Initialize the
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
8. using c++, Write a function method that determines the mean of all the values in an array of integers. Your mean function should call a separate function that you write that determines the sum. Don’t use built-in sum or mean gadgets, but roll your own.
USE C++!!
Given a string you need to print all possible strings that can be made by placing spaces (zero or one) in between them. The output should be printed in sorted increasing order of strings.
You don't need to read input or print anything. Your task is to complete the function vector<string> permutation(string S) which takes the string S as input parameters and returns the sorted array of the string denoting the different permutation (DON'T ADD '(' and ')' it will be handled by the driver code only).Expected Time Complexity: O(2^n)Expected Auxiliary Space: O(1)
CONSTRAINTS:1 < |S| < 10S only contains lowercase and Uppercase English letters.
(2) Now implement a convert_words() function, which has a list of words as a parameter, and returns a list of words all in lower case. Then
extend your program to prompt the user as before, but this time also convert the words to lower case using convert_words(), sort them, and
then print the list of lower case words again using print_words(). See the following: es ai
Enter a sentence (without punctuation): This Is a Sentence That Repeats this is a sentence that
repeats but has different words with Capitals
Sorted list of words:
Capitals Is Repeats Sentence That This a a but different has is repeats sentence that this with
words
Sorted list of words in lower case:
a a but capitals different has is is repeats repeats sentence sentence that that this this with
words
Chapter 8 Solutions
Problem Solving with C++ (10th Edition)
Ch. 8.1 - Prob. 1STECh. 8.1 - What C string will be stored in singingString...Ch. 8.1 - What (if anything) is wrong with the following...Ch. 8.1 - Suppose the function strlen (which returns the...Ch. 8.1 - Prob. 5STECh. 8.1 - How many characters are in each of the following...Ch. 8.1 - Prob. 7STECh. 8.1 - Given the following declaration and initialization...Ch. 8.1 - Given the declaration of a C-string variable,...Ch. 8.1 - Write code using a library function to copy the...
Ch. 8.1 - What string will be output when this code is run?...Ch. 8.1 - Prob. 12STECh. 8.1 - Consider the following code (and assume it is...Ch. 8.1 - Consider the following code (and assume it is...Ch. 8.2 - Consider the following code (and assume that it is...Ch. 8.2 - Prob. 16STECh. 8.2 - Consider the following code: string s1, s2...Ch. 8.2 - What is the output produced by the following code?...Ch. 8.3 - Is the following program legal? If so, what is the...Ch. 8.3 - What is the difference between the size and the...Ch. 8 - Create a C-string variable that contains a name,...Ch. 8 - Prob. 2PCh. 8 - Write a program that inputs a first and last name,...Ch. 8 - Write a function named firstLast2 that takes as...Ch. 8 - Write a function named swapFrontBack that takes as...Ch. 8 - Prob. 6PCh. 8 - Write a program that inputs two string variables,...Ch. 8 - Solution to Programming Project 8.1 Write a...Ch. 8 - Write a program that will read in a line of text...Ch. 8 - Give the function definition for the function with...Ch. 8 - Write a program that reads a persons name in the...Ch. 8 - Write a program that reads in a line of text and...Ch. 8 - Write a program that reads in a line of text and...Ch. 8 - Write a program that can be used to train the user...Ch. 8 - Write a sorting function that is similar to...Ch. 8 - Redo Programming Project 6 from Chapter 7, but...Ch. 8 - Redo Programming Project 5 from Chapter 7, but...Ch. 8 - Prob. 11PPCh. 8 - Write a program that inputs a time from the...Ch. 8 - Solution to Programming Project 8.14 Given the...Ch. 8 - Write a function that determines if two strings...Ch. 8 - Write a program that inputs two strings (either...Ch. 8 - Write a program that manages a list of up to 10...
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
- USE C++!! Given a string you need to print all possible strings that can be made by placing spaces (zero or one) in between them. The output should be printed in sorted increasing order of strings. You don't need to read input or print anything. Your task is to complete the function vector<string> permutation(string S) which takes the string S as input parameters and returns the sorted array of the string denoting the different permutation (DON'T ADD '(' and ')' it will be handled by the driver code only).Expected Time Complexity: O(2^n)Expected Auxiliary Space: O(1) CONSTRAINTS:1 < |S| < 10S only contains lowercase and Uppercase English letters. ATTACHED BELOW ARE THE REQUIRED DRIVER CODESarrow_forwardIn python. Include docstring. Please follow code requirements as listed below. Write a recursive function named is_subsequence that takes two string parameters and returns True if the first string is a subsequence of the second string, but returns False otherwise. We say that string A is a subsequence of string B if you can derive A by deleting zero or more letters from B without changing the order of the remaining letters. The empty string (which has zero characters) is considered a subsequence of any string (since you can derive it by deleting zero or more letters from any string). You can assume that the only characters in the strings will be lower case letters (though that shouldn't really affect your code). Note: subsequences are different than substrings, since the characters of a subsequence don't have to be consecutive. For example, 'aeiou' is a subsequence of 'faceitious', since all the characters appear in the same order, even though they're not consecutive. You may use…arrow_forwardWhat does the following code output?arrow_forward
- NEED CODING IN PYTHON OR JAVASCRIPT BUT NOT C++ consider an input string TAM of letters ‘A’, ‘M’, and ‘T’. This string, which is given by the user, ends with ‘#’. It should be stored in a table (or array), called TAMUK. The number of each of these letters is unknown. We have a function, called SWAP(TAM,i,j), which places the ith letter in the jth entry of string TAM and the jth letter in the ith entry of TAM. Note that SWAP(TAM,i,j) is defined for all integers i and j between 0 and length(TAM)–1, where length(TAM) is the number of letters of TAM. 1. Using our algorithmic language, write an algorithm, called Sort_TAM, which sorts the letters in the array TAMUK in a way that all T’s appear first, followed by all A’s, and followed by all M’s. The algorithm Sort_TAM should have one parameter: The array TAMUK. Also, your solution is correct only if the following four constraints are satisfied: - Constraint 1: Each letter (‘A’, ‘M’, or ‘T’) is evaluated only once. - Constraint 2: The…arrow_forwardiii. Add a function named lowercase() to this program that takes a list of uppercase letters as a parameter (e.g., x). This function must convert each uppercase letter in x to lowercase and return the list. Your function must use the ord() and chr() functions to solve this problem. You must NOT use the built-in lower() method. Hint: for any letter, the difference between its lowercase and uppercase ASCII values is 32. For example, ASCII values of 'a' and 'A' are 97 and 65, respectively; ASCII values of 'z' and 'Z' are 122 and 90, respectively.arrow_forwardin c++ 1. Write a function that takes a 1 Dimensional array and an integer n andreturns the number of times ‘n’ appears in the array. If ‘n’ does not appearin the array, return -1.2. Write a function that takes a 2 Dimensional array and returns the positionof the first row with an odd sum. Assume that the column size is fixed at 4.If no sum is odd, return -13. Write a class, “pie”, that has a number of slices (int slices) as a privateproperty. Construct the pie with a number of slices and remove a slice witha function. Tell the user how many slices are in the pie.arrow_forward
- (4) Implement the GetNumOfWords() function. GetNumOfWords() has a constant string as a parameter and returns the number of words in the string. Hint: Words end when a space is reached except for the last word in a sentence. Call GetNumOfWords() in the PrintMenu() function.Ex: Number of words: 35arrow_forwardPlease use Python when answering this question: Also could you please run a doctest for each solution in the output to make sure the code works and returns everything in the output. Write a function numPairs that accepts two arguments, a target number and a list of numbers. The function then returns the count of pairs of numbers from the list that sum to the target number. In the first example the answer is 2 because the pairs (0,3) and (1,2) both sum to 3. The pair can be two of the same number, e.g. (2,2) but only if the two 2’s are separate twos in the list. In the last example below, there are three 2’s, so there are three different pairs (2,2) so there are 5 pairs total that sum to 4. output: >>> numPairs( 3, [0,1,2,3] ) 2 >>> numPairs( 4, [0,1,2,3] ) 1 >>> numPairs( 6, [0,1,2,3] ) 0 >>>numPairs( 4, [0,1,2,3,4,2] ) 3 >>> numPairs( 4, [0,1,2,3,4,2,2] ) 5 >>> numPairs( 4, [0,1,2,3,4,2,2] )==5 TRUEarrow_forwardRewrite Exercise 3.5 using the following function to return the area of a regular polygon:def area(n, side):arrow_forward
- Create a class reversstring in c++andWrite a function called reversit () that reverses a C-string (an array of char). Use a forloop that swaps the first and last characters, then the second and next-to-last characters, and so on. The string should be passed to reversit () as an argument. Write a program to exercise reversit (). The program should get a string from the user, call reversit (), and print out the result.arrow_forwardWrite a C++ program that takes an char array of size twenty. Take input a sorted array from the user. Display the char array on console such that each row has only five elements separated by spaces. Then, you are required to then take a char x from the user and use binary search to search for element x in the array. Display the index of the element on the console. Also display two elements before and after the element x. Note: Don't use functions and strings.arrow_forwardsolve using c++. Let the user enter two arrays. Add(concatenation) the arrays into one extended array, by a user-defined function. Pass the extended array into another function that should return the length of the array passed to it. Input: First array: 2, 3, 4 Second array: 2, 4, 6 Output: Extended array is 2, 3, 4, 2, 4, 6 and its length is 6.arrow_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 Learning
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning