Question: Write a function in C++ called findMedian that takes two parameters - an array of int and the size of the array. The function should

Write a function in C++ called findMedian that takes two parameters - an array of int and the size of the array. The function should return the median of the array, which will require sorting the array (you can use the built-in sort function from the examples). This will change the original array, but that's okay for this assignment. If you're not familiar with calculating the median, please look that up. Remember that it's different for odd and even groups of values. If you are testing your code by calling it from a different file, remember to have a function prototype for findMedian in that file.

The file must be named: findMedian.cpp.

Example of using the built-in sort function

Write a function in C++ called findMedian that takes two parameters -

This program first initializes an array of ints. Next we use the built in sort function, which requires that you include . It takes two arguments - a pointer to the start of the array, and a pointer to the end of the array (arrived at here through pointer arithmetic). Afterward, when the array is printed out, the elements will be in ascending numeric order.

#include int mainCO int array[] = {23, 5, -10, 0, 0, 321, 1, 2, 99, 30); int size = 10; std::sort(array, array +size); for (int i = 0; 1

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!