double average Cconst double data[ size t n) Precondition: data is an array with
ID: 3848609 • Letter: D
Question
double average Cconst double data[ size t n) Precondition: data is an array with at least n components, and n 0. Postcondition: The value returned is the average of data10..dataln -1J. void compare(const double data[ J, size t n, double value); Precondition: data is an array with at least n components. Postcondition: The values dataloj through dataln 11 have been printed with a message saying whether they are above, below, or equal to value. int main double numbers Will point to the first component of an array size t array size double mean value Allocate an array of doubles to hold the user's input. cout "This program will compute the average of some numbers. The "; cout "numbers will be stored in an array of doubles that I allocate. n"; allocate doubles (numbers, array size) Read the user's input and compute the average. fill array numbers array size) mean value average numbers array size) Print the output. cout "The average is mean value end compare numbers array size, mean value) cout "This was a mean program.Explanation / Answer
In general, const qualifier is assigned to a variable so that its value will not change in the future. In fill_array, we are inputting the elements of data array so there is no need of const and on the other hand, in functions average and compare, we don't want these values to be changed or manipulated. That's why, we have put const qualifier on it.
Hope it helps, feels free to comment in case of any query.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.