Template for Function Design

Please use this template for each of the functions you are designing for your program.
Function name
pre-conditions = parameters
purpose in a sentence or so, which refers to the pre-conditions and the post-conditions
post-conditions = return values, changes to parameters, output, other state changes
Design = pseudocode - this is the bulk of the description

For "preconditions" above, write more than just "four parameters" or "2 parameters". You should write what each one is, what it means, and, if it is not clear, why that parameter is being sent to this function. You should state any assumptions that the function will be making about the parameters ("size is always positive", for example).

Post conditions should include the "result" of the function. If more than one result is returned, they should be listed in the order they are returned. If the function does any kind of actual output, that should be described also. It could be to the screen, a graphics window, or a file. If the function makes a change in any parameter that is mutable, that should be documented. If it is possible that this happens (not certain) describe the circumstances when it could happen. "The list of employees will be changed if the removal is successful."

Changes to files (opening, closing, reading from, writing to) need to be mentioned as a side effect of the function.

Design itself will be short or long depending on the job of the function. It could be one line if the function simply calculates something and returns it. It could be a screenful if it is a complex function. This is where you show the control structures that you are using.

Example: a function that will find the total of numbers in a file.
parameters: name of file
assumes numbers are one per line
purpose: to find the total of all numbers in the given file
postconditions: returns the total
will be zero if the file is empty. File will be closed at end of function.
  1. open file
  2. initialize accumulator (total)
  3. for all the lines in the file
  4.     add the value of the line to the total
  5. close file
  6. return total