Warning: foreach() argument must be of type array|object, bool given in /var/www/html/web/app/themes/studypress-core-theme/template-parts/header/mobile-offcanvas.php on line 20

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 drop_odd(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.

Short Answer

Expert verified
Answer: The 'output' function needed the 'const' keyword to be inserted before the 'a[]' parameter because this function only outputs the contents of the array without modifying anything. Adding 'const' ensures that the function does not modify the contents of the input array, preventing unintended behavior.

Step by step solution

01

Function 1: output

For the 'output' function, the input parameters are a double array 'a[]' and an integer 'size'. Since the only purpose of this function is to output the contents of the array without modifying anything, we can make the array parameter 'a[]' constant. The updated function signature should look like this: ```cpp void output(const double a[], int size); ```
02

Function 2: drop_odd

For the 'drop_odd' function, the input parameters are an integer array 'a[]' and an integer 'size'. This function modifies the contents of the array, specifically changing odd numbers to 0. Because it does modify the array, we cannot make the array parameter 'a[]' constant. Thus, there is no need to add a const keyword in function 2. It should remain as is: ```cpp void drop_odd(int a[], int size); ``` In conclusion, only the 'output' function needed the const keyword to be inserted, ensuring that the function does not modify the contents of the input array.

Unlock Step-by-Step Solutions & Ace Your Exams!

  • Full Textbook Solutions

    Get detailed explanations and key concepts

  • Unlimited Al creation

    Al flashcards, explanations, exams and more...

  • Ads-free access

    To over 500 millions flashcards

  • Money-back guarantee

    We refund you if you fail your exam.

Over 30 million students worldwide already upgrade their learning with Vaia!

One App. One Place for Learning.

All the tools & learning materials you need for study success - in one app.

Get started for free

Most popular questions from this chapter

In the array declaration double score[5] state the following: a. The array name b. The base type c. The declared size of the array d. The range of values that an index for this array can have e. One of the indexed variables (or elements) of this array

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(number); tripler(a[2]); tripler(a[3]); tripler(a[number]); tripler(a);

Write a function named out_of_order that takes as parameters an array of doubles 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 this array, 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.

What is the output of the following code? int i, temp[10]; for (i = 0; i < 10; i++) temp[i] = 2*i; for (i = 0; i < 10; i++) cout << temp[i] << " "; cout << endl; for (i = 0; i < 10; i = i + 2) cout << temp[i] << " ";

Write some \(\mathrm{C}++\) code that will fill an array a with 20 values of type int read in from the keyboard. You need not write a full program, just the code to do this, but do give the declarations for the array and for all variables.

See all solutions

Recommended explanations on Computer Science Textbooks

View all explanations

What do you think about this solution?

We value your feedback to improve our textbook solutions.

Study anywhere. Anytime. Across all devices.

Sign-up for free