CS 1323 Honors, Fall 1996
Individual Project 10
What to Hand In
Ecology Simulation - C Version
Due Wednesday, December 11, 4:30pm, FH303
Program Organization Chart
exhibiting the interactions between major program
of the program components you supply to complete this project
session transcript -
this interactive session will retrieve some parameters from
the keyboard, then chart a simulated ecology based
on those parameters.
Your program should interact with the keyboard and screen
in the same way as the Ecology Simulation program supplied
for Team Project B
The equations for simulating the ecology are as specified in
Individual Project 4 and
Team Project B.
- it will not ask for the dimensions of the chart
(it will display a chart of width 30 and height 20)
- it will reject a simulation period of more than
25 years (that is, 300 months)
- 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
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
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
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
- numericUtilities module
- functions to convert from analog to digital data and to compute
maximums and minimums
All of these functions are supplied
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
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
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
file #includes the
However, the graphSupport module also has some private functions.
These functions are defined in the
file. The public functions of the graphSuport module
(makeEmptyPicture and displayChart) are also defind the the
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
The ecologyEquations module provides another example.
It has a public function and a private function, so it has two
Both of these functions will defined in the
file. You will define the private function, nextRabbitCoyotePopulations,
by modifying the
file. The private function must be defined in that file because
that is the only way keep it from being a publically accessible
- The picture portion of the chart (using the terminology of
Individual Project 4)
is represented by an array of characters:
The first index of the array corresponds to the vertical
direction (lower indexes are nearer the bottom of the
picture), and the second index corresponds to the
horizontal direction (lower indexes are nearer the
left side of the picture).
- Read the document on
compiling and running
programs with multiple modules for tips on
compiling and running your program.
- As usual, follow the standards required in the
Project Style Guide
and the practices of the
Code of Conduct.