Project 10


The Projects

Your instructor may assign you one of the problems below. To solve your problem, write a program that reads the necessary information to compute and output the indicated values, as efficiently as possible.

Project #10.1: The median value of a sequence of numbers is a value v such that one half of the numbers are greater than v, and one half of the numbers are less than v. A simple algorithm to compute the median of a sequence is
  1. Let seq be the sequence.
  2. Let n be the number of values in the sequence.
  3. Sort seq.
  4. If n is an odd number:
        Return the middle value of the sorted sequence.
    Otherwise (n is even):
        Return the average of the two middle values in the sorted sequence.
Write a function that, given a vector of numbers, computes the median value of those numbers. Your function should use the STL sort() algorithm for the third step. Write a program that, given the name of a file containing an arbitrary sequence of numbers, computes and displays the median value of that sequence.

Project #10.2: A certain on-line testing program records student exam results in a text file, each line of which has the form:
name examScore
Write a program that analyzes student performance on an exam using the information from such a file (although you should store the data in vectors). The program should input the name of the text file, and then display the worst score, the best score, the average score, the standard deviation, and a histogram---a bar graph indicating the frequency with which a given score occurred. For example, if three people scored 74, five people scored 75, six people scored 76, no one scored 77 and two people scored 78, then that portion of the histogram should appear as:
74: ***
75: *****
76: ******
77:
78: **

Project #10.3: Each year a meteorologist creates a file containing a 12 monthly precipitation totals. Write a program that, given the names of two of these files, will create a file containing an easy-to-read analysis comparing the two sets of readings, including which of the two years was the wettest (and by how much), the average monthly precipitation for each year, and the wettest and driest months in each year.

Project #10.4: Write a program that, given the name of a text file, reads that file and counts the number of occurrences of each letter of the alphabet. Your program should use a vector of length 26 to count the occurrences of the 26 alphabetic letters and treat upper and lower-case instances of a letter as the same letter. (Hint #1: look up tolower() — testing the case isn't necessary. Hint #2: if ch is a char, then ch − 'a' is a valid C++ expression and will evaluate to 0 when ch is equal to 'a'.)

Run your program on several large text files.


Back to the Lab Exercise

Back to This Lab's Home Page


Report errors to Larry Nyhoff (nyhl@cs.calvin.edu)