Question: Write a second version of the median program ( median 2 . cc ) which repeatedly asks the user to enter a positive number, and

Write a second version of the median program (median2.cc) which repeatedly asks
the user to enter a positive number, and displays the median of the list of numbers
entered so far. You should start with an array of size 0 and increase the size of the
array each time a new number is entered. Exit the program when the user entered an
integer which is negative or 0. You should write the function:
int *resize(int *A, int n);
which increases the size of an array of n elements to n+1 elements. The first n elements
should be copied to the new array. The pointer to the array is returned, and the
original array passed into resize is deleted. An array of size 0 should be represented
by the nullptr pointer.
Sample session:
Enter a positive integer (<1 to quit): 6
The median so far is 6.
Enter a positive integer (<1 to quit): 10
The median so far is 8.
Enter a positive integer (<1 to quit): 3
The median so far is 6.
Enter a positive integer (<1 to quit): 7
The median so far is 6.5.
Enter a positive integer (<1 to quit): 9
The median so far is 7.
Enter a positive integer (<1 to quit): 2
2
The median so far is 6.5.
Enter a positive integer (<1 to quit): 10
The median so far is 7.
Enter a positive integer (<1 to quit): 0

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!