CMSC 104, Spring 2014

Homework 5

Out: Monday 5/5/14
Due: Before 11:59 PM on Monday, 5/12/14
Note that late homeworks will NOT be accepted.

The Objectives

The objective of this assignment is to become familiar with file input and output in C.

The Assignment

The C source file hw5.c contains a program to compute the correlation coefficient of two datasets. Unfortunately, the program is incomplete: there are three places in the file where you must provide the missing C code. The places where you need to write code are clearly marked with comments.

The file test.dat contains sample data that you must use with the program.

Note: you can download copies of the C file and the data file to your linux account using the commands:


wget http://userpages.umbc.edu/~cmarron/hw5.c
wget http://userpages.umbc.edu/~cmarron/test.dat

For your assignment to be complete, you must

  1. Complete the code as directed by the comments in the file;
  2. Add a file header comment with the usual information (file name, author, date, description); and
  3. Add any additional comments that would help a reader understand the code.

Be sure that you completed program compiles and runs. You can use the completed program to compute the correlation of the two datasets in the file test.dat. If the program works properly, it will produce an output file test.out containing the correlation coefficient of the two data sets.


linux1[10]% ls
hw5.c     test.dat
linux1[11]% gcc -Wall -ansi -lm hw5.c
linux1[12]% ./a.out
linux1[13]% ls
a.out     hw5.c     test.dat     test.out
linux1[14]% cat test.out
The correlation is 0.974416

Submit your work

Be sure that your completed program is called hw5.c and is in your hw5 directory. The next step is to submit your work.