Your instructor will 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. Following the pattern in the lab exercise, first, design using OCD; then code your design in C++ using stepwise translation; finally, test your program thoroughly.
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
Write a function that, given a vector of numbers, computes the median value of those numbers. Your function should use the STL
seqbe the sequence.
nbe the number of values in the sequence.
nis an odd number:
Return the middle value of the sorted sequence.
Return the average of the two middle values in the sorted sequence.
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: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: **Entries below the worst or above the best should not be displayed.
Project #10.3: Each year, the well-known meteorologist Dr. H. Tu Oh creates a file containing the year's 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 alphabetic letter in the file. Your program should use a
vectorof 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-'a'is a valid C++ expression and will evaluate to 0 when
chis equal to 'a'---try 'b', 'c', and 'd'!)
Run your program on several large text files.
Study the results looking for patterns; then write a paragraph addressing these two questions:
Submit this paragraph as part of your documentation.
- How would these numbers be useful to someone decoding a message encoded using the Caesar cipher?
- How would these numbers be useful to someone competing on the Wheel of Fortune game show?
Turn the following things: