Test 2 Redux CPS 08 April 11, 1995 Name: ____________________________ Honor code acknowledgement (signature) ____________________ Problem 1: Strawkcab (6 points) Write a function Reverse that reverses the elements of its array parameter a. For example: before: 10 20 30 40 50 60 70 after : 70 60 50 40 30 20 10 For maximal credit you may NOT define another !Vector! variable in the function Reverse. void Reverse(Vector & a, int numElts) // precondition: a represents: a0,a1, ..., a(numElts-1) // postcondition: a represnts: a(numElts - 1), ..., a1,a0 Problem 2: Modal: (6 points) Test scores in the range 0..100 (including 0 and 100) are stored in a file, one-per-line: 90 87 23 0 15 ... Write a program that reads all the scores in a file specified by the user and prints both the average score and the modal score. The modal score is the score that occurs most often of all the scores. If there are several scores that ``tie'' for modal score then all such scores should be printed, i.e., if scores of 95 and 98 occur 25 times and all other scores occur fewer than 25 times, then 95 and 98 should be printed. #include #include #include "CPstring.h" #include // for exit #include "vector.h" main() { int num; String filename; cout << "enter name of file: " cin >> filename; ifstream input(filename); if (! input){ cout << "could not open " << filename << endl; exit(1); } while (input >> num) { } } (For extra credit, determine the median score. The median is the score ``in the middle'', i.e., half the scores are greater and half are smaller. You can assume that the number of different scores is an odd number for this problem if you want to.)