CS 1323 Honors, Fall 1996

Individual Project 10
Ecology Simulation - C Version

Due Wednesday, December 11, 4:30pm, FH303

What to Hand In

Project Description

Your program should interact with the keyboard and screen in the same way as the Ecology Simulation program supplied for Team Project B (teamProjBMain.lhs), except that The equations for simulating the ecology are as specified in Individual Project 4 and Team Project B.

Program Organization

main module
directs keyboard interactions and screen displays
You will write the main module, which will import and make use of some of the public functions of the ecologyEquations, graphUtilities, and numericUtilities modules.
ecologyEquations module
function to compute an ecology trajectory, given its parameters
The public function to compute the trajectory is supplied (ecologyEquations.h, ecologyEquationsPrivate.h, ecologyEquations.c).
You will define a private function to compute populations for the next month, given the populations for the current month. Add your definition of this function to the file containing the C code for the ecologyEquations module (ecologyEquations.c) in place of a #include directive currently standing in its place. (This is an unusual #include directive because it refers to a .c file instead of a .h file - poor practice, used here only to facilitate testing the function without revealing its definition.)
graphUtilities module
functions to erase a picture, display a chart, and update a picture
Two of these functions are supplied in a submodule (graphSupport.h, graphSupportPrivate.h, graphSupport.c) whose interface is imported into the graphUtilities module from the graphSupport submodule.
You will define the function that updates a picture, following the interface specified in the header file for the graphUtilities module (graphUtilities.h).
numericUtilities module
functions to convert from analog to digital data and to compute maximums and minimums
All of these functions are supplied (numericSupport.h, numericSupport.c) except functions to compute the minimum and maximum of an array of one or more numbers of type double.
You will define these two functions following the interfaces specified in the header file for the module (numericUtilities.h). Note that the functions in the numericSupport submodule are imported into the numericUtilities module and also exported from that module (as with the public functions of the graphSupport submodule). Use the min and max functions defined in the submodule to help define the functions that compute minimums and maximums of arrays of numbers.

Modules in C

A module that contains both public and private functions will have two .h files, one declaring the public functions and the other declaring the private functions. Both .h files will be #included into to .c file containing the definitions of the public and private functions of the module.

The .c file must contain definitions of all of the private functions of the module; they are the ones with the static attribute. The reason the .c file of the module must contain all of the definitions of the private functions is that functions cannot be made available to one module without making them available to any module that might want to use them. So, to be private, they must be defined in the file where they are used.

The .c file for the module may contain the definitions of the public functions, but need not contain all of those definitions. Definitions of public functions may appear in another file, known as a supporting .c file for the module.

Public functions that are defined in a supporting .c file should be declared in a .h file of the same name. That .h file should be #included in both the supporting .c file itself, and in the .h file for the module. The #include that appears in the .h file of the module makes the interfaces of the public functions defined in the supporting .c file available to any module that #includes the .h file of the module.

Consider, for example, the graphUtilities module. Two of its public functions (makeEmptyPicture and displayChart) are defined in a supporting file (graphSupport.c). In this case, graphSupport is, itself, a module, and it has both public and private functions.

The public functions of the graphSupport module will be both imported to and exported from the graphUtilities module. That is why the graphUtilities.h file #includes the graphSupport.h file. However, the graphSupport module also has some private functions. These functions are defined in the graphSupport.c file. The public functions of the graphSuport module (makeEmptyPicture and displayChart) are also defind the the graphSupport.c file.

As for the graphUtilties module, two of its public functions are supplied by the graphSupport module. You will define its other public function (updatePicture) in the graphUtilites.c file, and this file will #include the graphUtilities.h file.

The ecologyEquations module provides another example. It has a public function and a private function, so it has two .h files: ecologyEquations.h and ecologyEquationsPrivate.h. Both of these functions will defined in the ecologyEquations.c file. You will define the private function, nextRabbitCoyotePopulations, by modifying the ecologyEquations.c file. The private function must be defined in that file because that is the only way keep it from being a publically accessible function.

Ground Rules

Last Modified: