Summary
of Marine Biology Case Study Classes
Display
one constructor, no private
variables
The display class displays a function for display. It has only one function
called "show." The show function gets a list of all the fish by calling
the Environment function env.AllFish(). It determines the number of rows
and columns needed in the display through the corresponding statements
int rows = env.NumRows(); and int cols = env.NumCols(); The function show
finds the position of the first fish to be displayed by determining if
the vector row and column for a certain position is defined. If it is,
it displays the fish using the ShowMe function and uses setw(WIDTH) to
place it in the correct location. If no fish is found in the position,
it instead displays a blank ““ ””.
Environ
one constructor, 2 private
variables (myFishCreated, myFishCount)
This class makes an environment available for the fish to swim in and it
also keeps track of the positions of the fishes with AllFish() const; when
the fishes need to move, it passes on a fishList to another function and
then use Update() to relocate the fish to a new position. It can also add
fish at empty positions. The private variables, myFishCreated and myFishCount
are used for the functions in the class to work with the fish. In the constructor
function ““Environment,”” the myWorld matrix is initialized to a size of
(0,0) as are myFishCreated and myFishCount. The function resizes the myWorld
matrix to determine the size of the environment based on user input of
the number of rows and columns. If the user enters information that does
not determine the size of it, it will display an error message. The NumRows()
and NumCols() functions of this class respectively return the number of
rows and columns in the environment matrix. The AllFish() function creates
an apvector of type Fish that has myFishCount # of fish and stores each
entry of the myWorld matrix in a position. The function returns this apvector.
The next function in the class called IsEmpty, returns true for each position
grid that does not have a fish. Otherwise it returns false.
Fish
2 constructors, 3 private
variables: int myId, Position myPos, bool amIDefined
This program creates fish for the environment to work with. It also assigns
each fish an unique id number. The Fish class also uses many private variables
like amIDefined, and myId to make sure each fish is defined and identified
properly. The class can also move fishes on a individual basis by moving
them in the environ class. The private variable, myPos, defines each fish's
position and can be accessed for display. The ID function returns the ID
of the fish if it meets the precondition that the fish is not undefined.
The location function returns the position of the fish via the value of
myPos. The fish class also allows the fish to be made into a stringized
form of the fish in an apstring by called to the ToString function. The
move function in the fish class moves the fish if it is possible. An object
of type Neighborhood is given the value of the number of empty spaces around
it by calling to the EmptyNeighbors function in the nbrhood class. A random
number is chosen in order to pick from the available empty spaces. The
environment is then updated. To be able to see your fish on the screen,
the ShowMe function must be used. This function returns a capital letter
corresponding to the integer ID of the fish, or a *. The fish class also
allows for fish to be added one by one to manually north, south, east,
or west using the EmptyNeighbors function. To check if there is an empty
space in the surrounding areas of the fish and add it to the space, the
AddIfEmpty function is called.
Nbrhood
one constructor, 2 private
variable: int myCount, apvector myList
This class keeps track of the environment neighborhood, the area around
each fish. Its critical use is to determine if each fish has room before
he moves. It can also return a string version of all the positions in the
neighborhood. Number of positions are also available for display. The private
variable, myCount, is used to keep track of the positions in the class.
The nbrhood class is used to return the status of the fish tank for example,
the size function returns the size of the fish tank using the myCount variable
because the myCount variable is the number of positions in the class. It
is able to return the index-th position in the Neighborhood via the Select
function because its parameters include an int variable with the index
value inside it. After, it returns the value of the index-th position by
checking its position in the apvector. By using an apvector variable, the
apvector can be extracted one by one and added to the apstring to create
one big string that represents the neighborhood. A position may be added
if there is space for it in the neighborhood. Because the apvector represents
the fish tank, the function gets apvector and if there is enough room for
another space, then it is added. If added, the myCount is incremented.
Position
2 constructors, 2 private
variables: int myRow, int myCol
The 2 constructors in this class define a position and can also be defined
when a position is specified. Its accessing function can return positions
that are adjacent to the current position. The accessing function of Row()
and Col() can be used to return current position (that's what myRow and
myCol is used for). Position also can return the position north of the
fish, south of the fish, east of the fish, and west of the fish. The North,
South, East, and West function returns the position respectively north,
south, east, and west. This is done by modifying the value of myRow and
myCol. In the north function, myRow is decremented. In the south function,
myRow is incremented. In the east function, myCol is incremented. In the
west function, myRow is decremented. The position class is vital to the
determining the position of a specific area in the fish tank, and the area
north, south, east, and west of that specific spot. The position class
can also be attached to an apstring. The position function can also be
used to prevent two fishes from moving into the same space.
RandGen
2 constructors, no private
variables
This class is used to generate random numbers for the other classes to
randomly move the fishes in their positions. Only integers and double type
numbers are available for return in the RandGen class. There are different
types of obtaining a random number. A random number can be generated by
different methods. Based on the parameters given by the user, a random
number can be made with only integers, with decimals and integers, with
numbers between 0 and 1, and numbers between zero and a specific number
provided by the user. In the marine biology case, a random integer is called
to represent the movement of the fish. This is because a fish moves randomly
throughout the environment. RandInt returns a random integer. RandReal
returns a random double.
Simulate
One constructor, no private
variables
This class simulates the movement of the fish. In the Step function, the
vector containing the fishList is declared and the environment is called.
It moves the fishes once in the environment. The Run function then moves
the fishes a number of times that is passed by value to the function, and
depends on the number of steps the user wants to see.
Untils
No constructors, no private
variables
This class contains 3 useful functions for use by other classes. The IntToString(int
n) returns n to string form. It is used in the ToString() function of the
Fish class to convert myId to a string.. This can be used for the id's
of the fishes. There is also void Sort(apvector & list, int numElts).
This is provided to sort the list top-down/left-right by position. There
is also the void DebugPrint(int level, const apstring & msg). The integer
parameter level specifies the amount of detail desired for debugging output.
The level parameter can be set by modifying utils.cpp.