MCX2 Marine Biology Case Study Worksheet #2 Mr. Gary Jaye
Implement these member functions as specified. Refer to header files and object diagrams as needed.
#1.
char Fish::ShowMe() const {
// postcondition: returns a character that can make me visible
}
#2. Default constructor
Fish::Fish() :
// Use constructor initializer list
{}
#3.Explicit value constructor
Fish::Fish(int id, const Position & pos) // Use constructor initializer list
:
{}
#4.
void Environment::AddFish(const Position & pos) {
// precondition: no fish already at pos, i.e., IsEmpty(pos)
// postcondition: fish created at pos
}
#5. See object diagram on p. 5 of 8 (Part 2)
RELEVANT PROTOTYPES:
1. Neighborhood Fish::EmptyNeighbors(const Environment & env, const Position & pos) const;
2. Position Neighborhood::Select(int index) const;
3. void Environment::Update(const Position & oldLoc, Fish & fish);
4. int RandGen::RandInt(int max); // *** postcondition: returns int in [0..max)
void Fish::Move(Environment & env) {
// precondition: Fish stored in env at Location()
// postcondition: Fish has moved to a new location in env (if possible)
}
#6.
apvector<Fish> Environment::AllFish() const {
// postcondition: returned vector (call it fishList) contains all fish in top-down, left-right order: top-left fish in fishList[0],
// bottom-right fish in fishList[fishList.length()-1]; # fish in environment is fishList.length()