CS35: Project 1

CS35: Programming and Problem Solving
Ray Ontko
Department of Computer Science
Earlham College

Due Monday, 1999/09/20

Choose one of the following programs for your first project. Write a program which implements the described functionality, and test it on one or more input files of your choosing. Turn in a print-out of the working program, a print-out of the input file, and a print-out of the output of your program (or, you can send all three to me in an e-mail).

  1. Imagine you are doing some simple textual analysis of Shakespearean sonnets. You have a hunch that most of the sonnets were actually written by the Bard himself, but a few of them seem to you to be of dubious origin. You wonder, perhaps, whether the relative frequency of letters in the sonnets will provide a clue; if the letter 'a' occurs with approximately the same frequency in all sonnets except one, then perhaps something is amiss. You need a program to help you.

    Write a program which reads character input and counts the number of occurrences for each letter of the alphabet, along with the total number of alphabetic letters read, and then prints a summary showing the percentage for each letter.

    The dialogue from your program should look something like this:

    $ ./letter_freq < sonnet_1.txt
    a 6.5 %
    b 2.3 %
    c 1.5 %
    ...
    x 0.0 %
    y 4.4 %
    z 0.1 %
    

    Of course, you will need to produce your own input file. In this example, the file "sonnet_1.txt" contains the text for a Shakespearean sonnet.

  2. Imagine you are doing water quality research using automated equipment which produces a file of numbers each day, one reading per line. After reading the instruction manual for the equipment, you managed to figure out how to download the files and have amassed 30 days worth of readings. As you start analyzing the data, you need to get a "feel" for the data; how many numbers are there in a particular file, what range of values are encountered, and what is the average and sum of values. You need a program to help you.

    Write a program which reads numeric input and calculates the minimum, maximum, average, sum, and count for the list of numbers entered, and then prints these values.

    The dialogue from your program should look something like this:

    $ ./simple_stat < 19990913.dat
    Count:     48
    Min:      139.000000
    Max:     1037.000000
    Avg:      603.942000
    Sum:    28989.216000
    $
    

    For testing purposes, you will need to produce your own input file. In this example, the file "19990913.dat" contained 48 numbers.

Copyright © 1999, Ray Ontko (rayo@ontko.com).