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
- Complete the code as directed by the comments in the file;
- Add a file header comment with the usual information (file name, author, date, description); and
- 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.
- Change to the
hw5
directory (usepwd
to check that you have done this correctly) and then submit the file to the projecthw5
using the command:linux1[6]% submit cmsc104_cmarron hw5 hw5.c linux1[7]%
- You can use the
submitls
command to check that you have submitted both files:linux1[8]% submitls cmsc104_cmarron hw5 total 5 drwxr-xr-x 2 cmarron rpc 2048 Mar 09 14:05 . drwxr-xr-x 43 cmarron rpc 2048 Mar 09 14:05 .. -rw-r--r-- 1 cmarron rpc 1858 May 09 14:05 hw5.c