In statistics when a set of values is sorted in ascending or

In statistics, when a set of values is sorted in ascending or descending order, its median is the middle value. If the set contains an even number of values, the median is the mean, or average, of the two middle values. Write a function that accepts as arguments the following: a. An array of integers b. An integer that indicates the number of elements in the array The function should determine the median of the array. This value should be returned as a double. (Assume the values in the array are already sorted.) You’ll create two arrays: one with three elements (e.g. 1, 3, 7) and one with four elements (e.g. 2, 4, 5, 8). Demonstrate your pointer prowess by using pointer notation instead of array notation in this function.

Solution

#include using namespace std; char again; int getMedian(double*, int); const int constant = 100; int main() { do { int number; double *array; int median = 0; cout << \"Enter the number of values in ascending or descending order: \"; cin >> number; array = new int[number]; for (int count=0; count < number; count++) { cout<<\"Enter number #\"<<(count+1)<<\": \"; cin >> array[count]; } median = getMedian(array, number); cout << \"The median is \" << median ; cout << \"\ Do you want to run this program again? Y/N: \"; cin >> again; } while (again == \'y\' || again == \'Y\'); return 0; } getMedian(double *array, int size) { int midIndex = 0; double median = 0; int size; if ((size % 2)!= 0) { midIndex = ((size - 1) / 2); median = array[midIndex]; return median; } else { midIndex = size / 2; median = ((array[midIndex] + array[midIndex +1]) /2); return median; } }
In statistics, when a set of values is sorted in ascending or descending order, its median is the middle value. If the set contains an even number of values, th

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site