Question: I'm having trouble with this assignment. This is the code I have so far. Thank you. #include using namespace std; int main() { int* grades

 I'm having trouble with this assignment. This is the code I

I'm having trouble with this assignment. This is the code I have so far. Thank you.

#include

using namespace std;

int main()

{

int* grades = nullptr;

int nGrades = 0;

double median;

cout

cin >> nGrades;

grades = new int[nGrades];

for(int i=0;i

{

cout

cin >> *(grades+1);

}

int total = 0;

for (int i = 0; i

{

total += *(grades+1);

}

if(nGrades%2==1)

{

median = (double)*(grades+(nGrades/2));

}

median = (double)(*(grades+(nGrades/2))+*(grades+(nGrades/2)))/2;

cout

}

Skill Practice Assignment 2 - Median Function Median Function: 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 teh array are already sorted.) Please use pointer notation rather than array notation in solving this problem. In order to assure us of using the same even and odd arrays, please use the following in your assignment // An array with an odd number of elements int odd[] = { 1, 2, 3, 4, 5, 6, 7}; II An array with an even number of elements int even[] = { 1, 2, 3, 4, 5, 6, 7, 8 }

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!