Question: Your program must read the standard input and write to the standard output. The program will read sequences of floating-point numbers (use type 'double') and

 Your program must read the standard input and write to the

Your program must read the standard input and write to the standard output. The program will read sequences of floating-point numbers (use type 'double') and for each sequence print the average and median of the sequence. Each sequence is preceded with the number of elements in the se- quence. So, the program will read first the number of elements of the sequence, then all elements of the sequence, print the average and median values, and repeat this process. The program will end the first time it reads a zero or negative number as the length of the sequence. The numbers are separated by whitespace Remember that for the median you need to sort the array, and if the array has an odd number of elements the median is the element exactly in the middle; otherwise, if the array has an even number of elements, then the median is average of the two middle elements. The output numbers must be rounded to three decimals, and must follow the format descrobed below Input The input consists of several sequences of floating-point numbers. Each sequence starts with a positive integer n, followed by n floating-point numbers, all separated by whitespace. The number 0 or a negative number is at the end of input. Output For each sequence of numbers, your program must print one line in the format: Avg: a Med: m where a is the sequence average, and m is the sequence median. There is exactly one space between the word Avg: and a, between a and Med: and between Med: and m. The numbers a and m must be printed with three digits precision. Sample input and output are given below Sample Input Sample Output Avg: 2.250 Med: 2.000 Avg: 3.667 Med: 5.000 1 4 3.0 Sample Output, witih visualized whitespace Avg:e2.250.Med: 2.000 Avg: -3.667 Med: -5.000 Note: is a space, and is a newline character The program must be implemented the following way: To calculate the median value, you should read numbers of a sequence in an array and sort them. You should declare the array after reading the sequence length, or you can assume that the array is at most 100 elements long and just declare an array of 100 elements. You must sort the array using the MergeSort algorithm. For this you must declare two functions that should be named merge_sort and merge or you can use similar names

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!