G22.2262-001, Fall 2002

Assignment 5

Due Date: Dec 5, 2002

 

 

In this assignment you are given two code fragments written in C.This code is undocumented and variable names are not at all descriptive of the items they represent.

 

Your task is to add comments to this code so that every step of the code is described correctly and to write a description of how to use the code (that is, user documentation).The description should include:

 

(1)  Purpose of the function

(2)  Description of each input argument

(3)  Description of output

 

About comments.

 

You do not need to add comments for EVERY line of code.You do need to provide a description of the logical steps that the function takes.†† Use your judgment to differentiate logical steps from one another.For example, the following pseudo code:

 

int t1 = a*a;

int t2 = b*b

sumsq = t1 + t2;

 

Needs only one comment (/* calculate the sum of the squares */).

 

In contrast, these comments (for each line)

 

/* multiply a times a */

/* multiply b times b */

/* add t1 to t2 */

 

are not very useful!They provide no more information than the code itself.

 

 

To help you decide where to add comments, Iíve inserted markers in the form:

 

/* ? */ ††††††††††††††††††††††† single line comment needed

/* ???? */††††††††††††††††††††††† comment block needed (one or more lines of description)

errexit(" ???? Ö††† replace ???? with descriptive error message

 

 

The two files that you need are foo.c and bar.c (follow their links to get the code).

 

You have to submit your commented versions of foo.c and bar.c.To be sure that we donít mix up your solution with those from another student, please place your name and student ID within a comment block at the beginning of each file (foo.c and bar.c).