Question: Hello! I'm really needing help on this coding assignment. Thanks in advance! I will rate :) Complete this program : add two functions (& their

Hello! I'm really needing help on this coding assignment. Thanks in advance! I will rate :)

Complete this program: add two functions (& their prototypes) that return the maximum and minimum value of an array of x elements. The program should ask the user for these x elements.

Hint: the functions will return a single integer value, and should have 2 parameters: the array (passed as a constant array), and the numbers of values in the array.

Question: do the min_element(...) and max_element(...) functions modify the arrays in any way? If not, then the array parameter (in both the function prototype and the function definition) should be declared "const" . While your functions will work just fine without the keyword const, it is better to use it here. That signals to readers of your code that the array will not be modified by the function, and would trigger a compiler error if you tried to modify the array inside the function. This is one of C++'s features that helps reduce human error.

Program should do the following:

1) Return the maximum and minimum value of an array of x elements

2) Move the task of querying the user for the array values to a function query_for_array(...) .

3) Add a function array_average(int array, int length); that returns the average value of the elements in the array and then add another function array_stats(...) that returns the min, max and average of an array.

4) Fill the array rand_array with 25 values using rand( ).

Code:

#include #include

using namespace std;

//......................add your prototypes here................

//..............................................................

int main(void) { int n = 10; int myarray[10]; // int rand_array[25] // for part 2d int val = 0; int mymin, mymax;

for(int i = 0;i < n;i++) { cout << "Enter the element No. " << i << "of the array "; cin >> val; myarray[i] = val; } // for part 2b, replace the above loop with a this function call, and write the function: // query_for_array(myarray, n); // for part 2c, add a function to calculate the average of an array, and a function to return all 3 values (min, max and average).

mymin = min_element(myarray, n); mymax = max_element(myarray, n); cout << "The minimum element of the array is " << mymin << endl;

cout << "The maximum element of the array is " << mymax << endl;

// for part 2d, add code here to fill rand_array[] with 25 random numbers, and then use your stats function // to find the min, max and average return 0; }

//.......................add your functions here....................

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!