Hints on exercise using struct example

This is the third programming milestone

  1. Take the example and adapt it to read in a series of records typed in at the keyboard and print each record to the screen in turn. After it has read each record it should prompt the user whether to continue, asking then to type a 'y' to continue or a 'n' to stop there. When accepting input for a record, the program should prompt for the input required for each line or field.
    This requires you to wrap a while loop around the input part of the program. The loop should terminate when the user types anything other than 'y' at the end of a record.

    The prompting for input merely requires the addition of suitable printf statements.

  2. Consider the frequency counting example again. Now you should enhance it by using a struct to store information. This should include the mean, standard deviation and the array of frequencies. The program should now report on this information at the end of the series, prompting them to type 'm' for just the mean, 's' for both the mean and standard deviation or 'a' for mean, standard deviation and histogram.
    The struct obviously needs fields for mean, standard deviation and an array of frequencies. It will also need to record the number of items read and the cumulative total of their values, since the mean is this total divided by the number of items. The standard deviation can be computed if you also keep the sum of the squares of the values, since the following formula gives you the standard deviation:

    Square Root(n * (sum of squares of values - square of sum of values)/(n*(n-1)))
    where n is the number of items read.

    Back to the questions.


    Back to the struct example note.