Problem Solving with C++, Student Value Edition
10th Edition
ISBN: 9780134543680
Author: Walter Savitch
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
The goal is to rewrite the function, below, such that passes in a different list of parameters, particularly eliminating the need to pass low and high for each recursive call to binary_search.
defbinary_search(nums,low,high,item):
mid=(low+high)//2iflow>high:returnFalse #The item doesn't exist in the list!elifnums[mid]==item:returnTrue# The item exists in the list!elifitem<nums[mid]:returnbinary_search(nums,low,mid-1,item)else:returnbinary_search(nums,mid+1,high,item)
The new function should be prototyped below. The number of changes between the given version, and the one requested is not significant.
defbinary_search(nums,item):pass# Remove this and fill in with your code
Tip: If you consider that high and low are used to create a smaller version of our problem to be processed recursively, the version requested will do the same thing, just through a different, more Pythonic technique.
1.) Write a function double power(double x, int n) that will compute xn
12. Consider the recursive function int gcd( int a, int b)
int gcd( int a, int b){
if (b > a) return gcd(b,a);
if ( b == 0 ) return a;
return gcd( b, a% b);
}
How many invocation (calls) of the gcd() function will be made by the call gcd(72, 30)?
Chapter 8 Solutions
Problem Solving with C++, Student Value 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
- Write a C++ function, bool ok(int q[]), which takes an array q and returns true if the array represents a valid configuration of the eight queens and returns false otherwise.arrow_forward09. Python Write the in_order() function, which has a list of integers as a parameter, and returns True if the integers are sorted (in order from low to high) or False otherwise. The program outputs "In order" if the list is sorted, or "Not in order" if the list is not sorted. Ex: If the list passed to the in_order() function is [5, 6, 7, 8, 3], then the function returns False and the program outputs: Not in order Ex: If the list passed to the in_order() function is [5, 6, 7, 8, 10], then the function returns True and the program outputs: In order Note: Use a for loop. DO NOT use sorted() or sort()..arrow_forward1. In C++, Take inputs from user and store them in an Array?arrow_forward
- What is wrong with the following C++ function? void Maximum(int a, int b, int& max) { if (a > b) max = a; else max = b; return max; }arrow_forwardWrite a function that prints the following pattern of n lines. * *+* * * * * + **+*+*+*+*arrow_forwardWrite a C function to search for a given number using binary search in a given array ofsorted numbers, sorted in ascending order. The function should return the index wherethe number is found, or zero otherwisearrow_forward
- write a program c ++ to find the sum of the following series?arrow_forwardGive a recursive definition of the function that takes ? (?ℎ??? ? ∈ ℕ) and gives the number of strings of length ? over the alphabet Σ = {0,1,2} that contain two consecutive symbols that are the same.arrow_forwardImplement the following function, without using any data structure. /* Given two vectors of chars, check if the two vectors are permutations of each other, i.e., they contains same values, in same or different order.e.g., V1=[‘a’,’b’,’a’] and V2=[‘b’,’a’,’a’] stores same multi-set of data points: i.e., both contains two ‘a’, and one ‘b’. e.g., V3=[‘a’,’c’,’t’,’a’] and V4=[‘a’,’c’,’t’] are not same multi-set. V3 contains two ‘a’s, while V4 has only one ‘a’. Note: when considering multiset, the number of occurrences matters. @param list1, list2: two vectors of chars @pre: list1, list2 have been initialized @post: return true if list1 and list2 stores same values (in same or different order); return false, if not. */ bool SameMultiSet (vector<char> list1, vector<char> list2)arrow_forward
- The problem was to write a program that allocates the integers 1-8 to the squares in the eight numbers in a cross figure, subject to the restrictions that no two adjacent squares contain consecutive integers. By adjacent, we mean vertically, horizontally, or diagonally. Given, the labeling of the eight numbers in a cross figure, use C++ to write the bool okay (int q[], int c) function that includes the helper array.arrow_forward8. 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.arrow_forwardwrite another function drawLine(int x, int y) in the above code. this function should return length of lines by same method i.e., subtracting y from x.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