CS31 Lab 4: C Pointers

Due before midnight on February 27th

Lab 4 Goals:

Contents:

Getting Starting Point Code

Here are the new partnerships. The course webpage has a section on expectations for working with partners.

Both you and your partner should:

  1. On the CS system, cd into your cs31/labs subdirectory
    cd ~/cs31/labs
    
  2. Get your Lab04 ssh-URL from the GitHub server for our class: CS31-s18
  3. Clone a local copy of your shared repo in your private cs31/labs subdirectory:
    git clone [your_Lab04_URL]
    
You should see the following files in your repo:
Makefile       grades.c     grades1.txt  readfile.c
QUESTIONNAIRE  grades0.txt  grades2.txt  readfile.h
For more detailed instructions see the the Using git guide.

Assignment Overview

Educators sometimes want a statistical analysis of a set of exam scores. These analyses could be done for an exam from a single class or an exam from an entire school district. A useful tool would be a program that computes statistical results for any size data set (i.e. it would work for ten values or for thousands, without re-compilation).

We will implement such a program this week. The program should take as a command-line argument the name of a file that contains a bunch of floats, one per line. The program then stores these values, computes a bunch of statistics about them, and prints the result to the user.

The starting point code comes with three input files that you can use to test your solution.

This program needs the readfile library and the math library. We have given you a Makefile that links in these libraries, so you should use the Makefile to compile. By reading the Makefile, you can see how the executable is built from a .c file and a .o file. The -lm flag tells gcc to link in the math library.

grades.c has the starting point code for your program. It contains a prototype for the get_values function that you need to implement, and it has some code in main that copies the file name given at the command line into a string local variable.

Your program should do the following:

  1. Make a call to get_values, passing in the name of the file containing the values, and passing in two values by reference: the address of an int variable to store the size of the array (number of values read in); and the address of an int variable to store the total capacity of the array (number of values allocated).

    get_values returns an array of float values initialized to the values read in from the file, or returns NULL on error (like if malloc fails or if the file cannot be opened). It dynamically allocates the array it returns and uses a doubling re-allocation algorithm if it runs out of space (see the requirements section for details about this algorithm).

  2. Compute the maximum, minimum, mean, median, and standard deviation of the set of grade values. Print out the total number of grades and each of these measures.

  3. Print out a histogram from the set of grade values.

    Each histogram bucket counts the number of exam scores in a particular range: 0-9, 10-19, 20-29, etc. Exam grades that have a fractional component (e.g. 89.75) should be counted as being in a histogram bucket range based on their whole number part only (e.g. 89.75 is a grade in the 80's not a grade in the 90's).

  4. Print the amount of unused capacity in the array storing the grade values.
The statistics you need to compute are:
  1. mean: the average of the set of values. For example, if the set is: 5, 6, 4, 2, 7, the mean is 4.8 (24.0/5).
  2. median: the middle value in the set of values. For example, if the set is: 5, 6, 4, 2, 7, the median value is 5 (2 and 4 are smaller and 6 and 7 are larger).
  3. stddev: is given by the following formula:

    s = 1 N-1 i=1 N x i - x - 2
    Where N is the number of values, xi is the ith value, and x- is the mean (average) value.

Sample Output

Here is sample output from a working program run on the three input files that were included with the starting point code. You should also test your program on other input files that you create.


Requirements

Hints, Tips, and Resources
Extra Challenge

This is not required, so don't attempt this challenge until you have finished all other parts of this lab.

Extra challenge

Submitting

There is a QUESTIONNAIRE file for you to fill out and submit with your lab solution. Your answers to the questionnaire will not affect your grade.

Only one member of your partnership needs to git push your solution before the deadline.