Problem Solving with C++ (9th Edition)
9th Edition
ISBN: 9780133591743
Author: Walter Savitch
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Textbook Question
Chapter 17.1, Problem 5STE
Display 7.10 shows a function called search, which searches an array for a specified integer. Give a function template version of search that can be used to search an array of elements of any type. Give both the function declaration and the function definition for the template. (Hint: It is almost identical to the function given in Display 7.10.)
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
3) Create a function named "makeThemOdd". The function should accept a parameter named "numberArray". Use the higher order function map() to create a new array that contains all the numbers from the original parameter array but adds 1 to each even number. The new array should only have odd numbers in it. Return the new array.
// Use this array to test your function:const testingArray = [1, 2, 4, 17, 19, 20, 21];
Write a template for a function that displays the contents of an array of any data type.
Write a program that has a declaration in main() to store the following numbers in an array named temps: 6.5, 7.2,7.5, 8.3, 8.6, 9.4, 9.6, 9.8, and 10.0. There should be a function call to show() that accepts the temps array as aparameter named temps and then displays the numbers in the array.
Chapter 17 Solutions
Problem Solving with C++ (9th Edition)
Ch. 17.1 - Write a function template named maximum. The...Ch. 17.1 - Prob. 2STECh. 17.1 - Define or characterize the template facility for...Ch. 17.1 - Prob. 4STECh. 17.1 - Display 7.10 shows a function called search, which...Ch. 17.1 - Prob. 6STECh. 17.2 - Give the definition for the member function...Ch. 17.2 - Give the definition for the constructor with zero...Ch. 17.2 - Give the definition of a template class called...Ch. 17.2 - Is the following true or false? Friends are used...
Ch. 17 - Write a function template for a function that has...Ch. 17 - Prob. 2PCh. 17 - Prob. 3PCh. 17 - Redo Programming Project 3 in Chapter 7, but this...Ch. 17 - Display 17.3 gives a template function for sorting...Ch. 17 - (This project requires that you know what a stack...Ch. 17 - Prob. 6PPCh. 17 - Prob. 7PPCh. 17 - This project requires that you complete...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
The spreadsheet in Microsoft Excel file Ch01Ex01_U10e.xlsx contains records of employee activity on special pro...
Using MIS (10th Edition)
Suppose that =0.075 (in fps units, with g=32ft/s2 ) in Eq. (15) for a paratrooper falling with parachute open. ...
Differential Equations: Computing and Modeling (5th Edition), Edwards, Penney & Calvis
Suppose a computer contained 512MB (MiB) of main memory, and an operating system needed to create a virtual mem...
Computer Science: An Overview (13th Edition) (What's New in Computer Science)
Practice Problem 12.4 (solution page 1036) In the server in Figure 12.8, we are careful to reinitialize the poo...
Computer Systems: A Programmer's Perspective (3rd Edition)
Tuition Increase At one college, the tuition for a full-time student is 8,000 per semester. It has been announc...
Starting Out with Python (4th Edition)
Convert the following iterative method to one that uses recursion: public static void sign(int n) { while (n 0...
Starting Out with Java: Early Objects (6th Edition)
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
- In java there must be at least two calls to the function with different arguments and the output must clearly show the task being performed. (ONLY ARRAYS or ARRAYLIST) Develop a function that accepts an array and returns true if the array contains any duplicate values or false if none of the values are repeated. Develop a function that returns true if the elements are in decreasing order and false otherwise. A “peak” is a value in an array that is preceded and followed by a strictly lower value. For example, in the array {2, 12, 9, 8, 5, 7, 3, 9} the values 12 and 7 are peaks. Develop a function that returns the number of peaks in an array of integers. Note that the first element does not have a preceding element and the last element is not followed by anything, so neither the first nor last elements can be peaks. Develop a function that finds the starting index of the longest subsequence of values that is strictly increasing. For example, given the array {12, 3, 7, 5, 9, 8,…arrow_forward1. Write an Arduino program that globally declares an array of size fifteen. The array data type is int. Write a function that fills the array with random values in the range [low, high]. The function has two parameters: low, high. The array is not a function parameter because it has been declared globally. Write a function that serially tranmits the array data. The function has one parameter that controls the number of array elements printed on the same line. For example, assume the function is called printArray. If we want 3 array elements to be printed on one line, then the function call is printArray(3). We would see something like this for output: Array -3 14 -3 2 11 -9 7 10 -4 -2 8 See how there are 3 values printed per line? 3 is the value passed to the function parameter that controls the number of array elements printed on one line. There should be at least one space between array elements printed. In the loop function, call the function that fills the array with random values…arrow_forwardRewrite the client program to use the Baby class that you have done using ArrayList. You should also have the following function in this new client program: a) Enter details for each baby (name and age) and thus populate the Baby ArrayList b) Calculate and display the average age of all babies in the ArrayList c) Ask the user to enter the name of a baby, and then remove it from the ArrayList d) Allow the user to add new baby information in the ArrayList e) Output the details of each baby from the ArrayList (name and age) Compare this client program using the ArrayList with the client program you have done using array, comment on the differences between the two. Modify your client program in the last question, by adding a sort function such that when that option is selected, it sorts the ArrayList using the baby names in alphabetical order and output the details in the sorted ArrayList to a CSV (sortedbabylist.csv) file. public class Baby { private String name; private int age;…arrow_forward
- 1. Define a struct for a soccer player that stores their name, jersey number, and total points scored. 2. Using the struct in #1, write a function that takes an array of soccer players and its size as arguments and returns the average number of points scored by the players.3. Using the struct in #1, write a function that takes an array of soccer players and its size as arguments and returns the index of the player who scored the most points.4. Write a Circle class that has the following member variables:• radius : a double• pi : a double initialized with the value 3.14159The class should have the following member functions:• Default Constructor. A default constructor that sets radius to 0.0.• Constructor. Accepts the radius of the circle as an argument.• setRadius. A mutator function for the radius variable.• getRadius. An accessor function for the radius variable.• getArea. Returns the area of the circle, which is calculated as area = pi * radius * radius• getCircumference. Returns…arrow_forwardC++ CODEarrow_forward1. Write a Swift function that takes an array as a parameter and returns a boolean value whether the value 0 is present in the array or not.arrow_forward
- Write a function that accepts an int array and the array’s size as arguments. The function should create a new array that is two elements larger than the argument array. The first two elements of the new array should be set to 0. Element 0 of the argument array should be copied to element 2 of the array, element 1 of the argument array should be copied to element 3 of the new array, and so forth. The function should return a pointer to the new array. Demonstrate the function in a complete program.arrow_forwardIn java Develop a function that accepts an array and returns true if the array contains any duplicate values or false if none of the values are repeated. Develop a function that returns true if the elements are in decreasing order and false otherwise. A “peak” is a value in an array that is preceded and followed by a strictly lower value. For example, in the array {2, 12, 9, 8, 5, 7, 3, 9} the values 12 and 7 are peaks. Develop a function that returns the number of peaks in an array of integers. Note that the first element does not have a preceding element and the last element is not followed by anything, so neither the first nor last elements can be peaks. Develop a function that finds the starting index of the longest subsequence of values that is strictly increasing. For example, given the array {12, 3, 7, 5, 9, 8, 1, 4, 6}, the function would return 6, since the subsequence {1, 4, 6} is the longest that is strictly increasing. Develop a function that takes a string…arrow_forward1) Write a program in C that stores a list of employee records in an array of structs. Each employee record should contain the following fields: Name (string), Age (int), Salary (float), Department (string). The program should prompt the user to enter the name of an employee, and then search the array of employee records for an employee with a matching name. If a matching employee is found, the program should print out the employee's age, salary, and department. If no matching employee is found, the program should print an error message. The program should use a linear search algorithm to find a matching employee in the array. If the employee's age is greater than 50, their salary should be multiplied by 1.1. If the employee's age is less than or equal to 50, their salary should be divided by 1.2. 2) Write a C program that defines a function called 'multiply_by_two' that takes an integer as an argument and returns the result of multiplying it by 2. The main function of the program…arrow_forward
- Revise the following Course class implementation in the following c++ code When adding a new student to the course, if the array capacity is exceeded, increase the array size by creating a new larger array and copying the contents of the current array to it. Implement the dropStudent function. Add a new function named clear() that removes all students from the course. Implement the destructor and copy constructor to perform a deep copy in the class. Write a test program that creates a course, adds three students, removes one, and displays the students in the course.arrow_forwardin c++ Write a user-defined function that takes an array and the size of the array as parameters, and returns the number of elements whose values are between 10 and 20 in the array. Define and initialize an array with 10 elements in main() function and use your user-defined function to display the result.arrow_forwardImplement a function that finds the number of values that are less than 0 and the number of values greater than 0 stored in an array of integers. Assume the array is the partially filled array from the previous question, and uses 0 to indicate the end of values stored in it. (18 pts) Note: the results should be passed back to the caller, not directly displayed in the function. Also note, as the following code template requires, the function’s return type is void. Please finish the function header, and function implementation. Hint.. In the beginning, set the lessThan and greaterThan values to be 0. Then as you scan through the array elements one by one, compare the next array element with 0. If the element is greater, update your greaterThan count; otherwise, if the element is less, update the lessThan count, otherwise do nothing. Continue until you see the value 0. GIVEN CODE: #include <iostream>using namespace std; // Find the number of values stored that is less than 0…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education
Definition of Array; Author: Neso Academy;https://www.youtube.com/watch?v=55l-aZ7_F24;License: Standard Youtube License