273-422 OBJECT-ORIENTED DESIGN Assignment # 2 ----------------------------------------------- Write a C++ program which reads in a data file of integers (one integer per line; first line gives the number of integers via a statement of the form: num_values 38652 ) and writes out to a file the integers in numerical order (lowest to highest). The program should print out (to stdout) the following values: 1) The number of values 2) the average of the values (E.g. if the data is 35 23 -10 17, the average is ((35 + 23 + -10 + 17) / 4.0) = 16.25 3) the square-root of the average of the squares of the values (E.g. with the above data, this is sqrt((35*35 + 23*23 + (-10)*(-10) + 17*17) / 4.0) = 23.146 Requirements: ------------ Your program should expect the data file to be named "input.txt" and should handle incorrectly formatted input by printing an error message to stderr and exiting. There should be no arbitrary limit on the size of the data file. Your program should make use of the standard library function 'qsort' for sorting the data. Your program should output the ordered list of integers to a file named "output.txt" using the same format as was used for the input file. The calculation of the two average values should be done via one function named 'statistics' which takes an array of integers as input and gives back the two average values via output-parameters. This function should have a declaration like: void statistics(const int *values, int num_values, float *avg, float *rms); Implementation notes: -------------------- Your program should allocate memory space for an array of integers after it finds out how many data values there are by reading the first line of the input file. When reading the input file, you need to check for at least the following problems relating to bad input: 1) the first line does not follow the specification for giving the number of data values to follow 2) there are non-integer data in the file 3) there are fewer integers than specified by the first line 4) there are more integers than specified by the first line You should have a separate error message for each of these possible problems. On the course web site I have provided some sample data files as well as an example program illustrating the use of 'qsort'. Concepts required: ----------------- file handling, arrays, pointers, memory allocation, output-parameters, qsort