C++ 11. Consider the following function definition: void tripler(int& n) { n = 3
ID: 3761637 • Letter: C
Question
C++
11. Consider the following function definition: void tripler(int& n) { n = 3*n; } Which of the following are acceptable function calls? int a[3] = {4, 5, 6}, number = 2; tripler(a[2]); tripler(a[3]); tripler(a[number]); tripler(a); tripler(number);
12. What (if anything) is wrong with the following code? int b[5] = {1, 2, 3, 4, 5}; for (int i = 1; i <= 5; i++) tripler(b[i]);
13. Write a function definition for a function called oneMore, which has a formal parameter for an array of integers and increases the value of each array element by 1. Add any other formal parameters that are needed.
14. Consider the following function definition: void too2(int a[], int howMany) { for (int index = 0; index < howMany; index++) a[index] = 2; } Which of the following are acceptable function calls? int myArray[29]; too2(myArray, 29); too2(myArray, 10); too2(myArray, 55); “Hey too2. Please come over here.” int yourArray[100]; too2(yourArray, 100); too2(myArray[3], 29);
15. Insert const before any of the following array parameters that can be changed to constant array parameters. void output(double a[], int size); //Precondition: a[0] through a[size - 1] have values. //Postcondition: a[0] through a[size - 1] have been written out. void dropOdd(int a[], int size); //Precondition: a[0] through a[size - 1] have values. //Postcondition: All odd numbers in a[0] through a[size - 1] //have been changed to 0.
16. Write a function named outOfOrder that takes as parameters an array of double and an int parameter named size and returns a value of type int. This function will test this array for being out of order, meaning that the array violates the following condition: a[0] <= a[1] <= a[2] <= ... The function returns -1 if the elements are not out of order; otherwise, it will return the index of the first element of the array that is out of order. For example, consider the declaration double a[10] = {1.2, 2.1, 3.3, 2.5, 4.5, 7.9, 5.4, 8.7, 9.9, 1.0}; In the array above, a[2] and a[3] are the first pair out of order and a[3] is the first element out of order, so the function returns 3. If the array were sorted, the function would return -1.
Explanation / Answer
12.
13.
14.
15.
16.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.