Topical Information

This lab should provide you with practice in file handling, stream formatting, and some string manipulation. classes might come in handy, too.

Background Information

In biology, studied organisms often exhibit paired traits (some are tall and others short; some are round and others wrinkled; some are bald and others have hair; etc.). Upon closer inspection, we can determine that many are truly in between (showing a sort of average of the traits -- medium height; just a little wrinkly; sparse hair coverage; etc.).

Given counts of how many individuals exhibit a trait completely and how many exhibit the traits in combination within a group, we can estimate the rate at which each of the trait pair occurs in the population. Take half the middle trait frenquency and add it to each of the paired-trait frenquencies. (This is because the middle trait is like an average of the two paired traits.)

For instance, suppose that 30 pea plants are tested for the roundness of their peas (i.e. how round their peas are). Of the 30 plants, 16 are found to produce really round peas, 4 produce really wrinkled peas, and the rest produce somewhat wrinkled peas.

    O O O O O O O O O O

    @ @ @ @ @ @ @ @ @ @

    O O O O O O ~ ~ ~ ~

    Legend:  Round       O
             Wrinkled    ~
             Middle-Mix  @

To calculate the rate at which roundness occurs in this group of pea plants, we take 16/30 (the round trait frequency) and add it to 10/60 (half the middle trait frequency) to get 42/60 or 0.70 or 70%.

    16     10         16     10     1     16     10     32 + 10     42
   ---- + ---- / 2 = ---- + ---- * --- = ---- + ---- = --------- = ---- = 0.70 = 70%
    30     30         30     30     2     30     60       60        60

So 70% of the population shows the round pea trait. How many have the wrinkled trait? Although we could do it the long way (4/30 + 10/60 = 18/60), we can also merely subtract the round trait rate from 100% to find how many are wrinkled. (After all, each pea plant is one or the other -- there are only two traits here.) This gives us 30% (the same as the 18/60 calculated above).

Program Information

Write a program to calculate the rate for two different traits in a population. In the user's data file (ask them for the name) you'll find the size of the population overall, the name of the creature (roach, bear, trout, etc.), the name of the experiment (Joan's kitchen, Rocky Mountains, Mississippi River -- Illinois Segment 1A, etc.), the name of each trait (round and wrinkled, tall and short, blue and green, etc.), and the count of each trait displayed "purely" in the population. At least one such set of data will be present for each trait pair under study in each creature. See the sample data file for details.

As you read in the data from the file calculate the count of the middle trait individuals and the rates at which the two traits occur in the population. Once calculated, display all of this information in a nice way (include all input and calculated data in the output; on the first line, center the experiment name; on the second line, center the creature name) onto an output file (again, ask the user for the name). See the sample results file for details.

Be sure you allow the user to enter the names of both the input file and the output file. Also be sure to test for the proper opening of both files.

Your main program might look something like this:

   open files -- check for validity
   input from infile
   while !infile.eof
      output to outfile
   close files

Don't forget about the possible occasion when there are no experimental results in the file at all!

Thought Provoking Questions

  1. How might a class help you in this program? (What data do you have to encapsulate? What behaviors need to be available for this data?)

  2. What do you do if there are no experiments in the file?

  3. How can you skip those comments at the top of the data file?

  4. How can you get the name to be centered?

  5. How can you line up the additions nicely?

  6. How might you easily determine the width of the population numbers to help you line up the addition? (Hint: Logarithms might prove handy here...)

This assignment is (Level 3).