Programming II  Mean, median, and mode 

Assignment: Program p01 finds the mean, median, and mode in a list of integers found in an input file: a sample of such a file can be found in the class directory ~tt/cs2613/i01.dat. The list may have more than or fewer than the number of integers in file i01.dat. The section titled Input File illustrates the format of the input file. The section titled Display and Keyboard Input shows the dialog where the user instructs program p01 to name input and output files. The section title Output File depicts how the output is formatted. Mean The mean is the sum of the sampled values divided by the number of values in the sample (e.g. the mean of {3, 3, 5, 9, 11} is 6.2). Median The median of a finite list of numbers can be found by arranging all the values from lowest value to highest value and selecting the middle one (e.g., the median of {3, 3, 5, 9, 11} is 5). When the list contains an even number of values, the median is computed by averaging the two middle values. For example, the median value of the list {3, 4, 6, 7, 9, 10} is the average of 6 and 7 equaling 6.5. Mode The mode is the value that appears most often in a set of data (e.g., the median of {3, 3, 5, 9, 11} is 3). Prohibition: Use of the C++ Standard Template Library is prohibited in the implementation of this project. Program Files: Project 1 consists of files p01.cpp, List01.h, List01.cpp, and p01make. Project file names are exactly as given. Failure to employ the foregoing names will result in a score of zero (0) for this project Project files must be stored in the root directory of your student account. Failure to store project files in the root directory of your student account will result in a score of zero (0) for this project. File Description p01.cpp File p01.cpp contains functions that process command line arguments and direct the process of reading, sorting, and printing the list. List01.h File List01.h defines class List. List01.cpp File List01.cpp contains the implementation of member functions in class List. p01make File p01make contains instructions that compile and link the files of project 1. File p01 is the executable created by the instructions in file p01make. Instructions in file p01make are executed by the UNIX utility make. 1 Programming II Mean, median, and mode CMSC 2613 Project p01 Command Line: Project 1 can be invoked with zero, one, or two program parameters. The first program parameter is the input file name. The second parameter is the output file name. Sample command lines together with corresponding actions by program p01 are shown below. Boldfaced type indicates data entered at the keyboard by the user. $ p01 Enter the input file name: i01.dat Enter the output file name: o01.dat $ p01 i01.dat Enter the output file name: o01.dat $ p01 i01.dat o01.dat Display and Keyboard Input: In the dialog below, the user enters text shown in bold. Sample Input File: 47 5 10 6 -2 3 -5 7 -11 13 -17 19 -23 29 -31 37 41 -43 47 -53 57 -67 -051 5000 33 Note: The list may have more than or fewer than the number of integers in this sample. Output File Specification: The mean, median, and mode are printed on separate lines. The titles, “Mean”, “Median”, and “Mode” are printed left justified in a field of 10 spaces. An equal sign, “=”, is printed in column 11. The value of the mean, median, and mode is printed right justified in a field of 10 spaces. The mean and median are floating-point values and printed in fixed format with two fractional digits. Sample Output File. Mean = 202.04 Median = 6 Mode = 47 (The values shown above were computed for the sample input file on the previous page.) 2
Powered by