CPlusOOP
SiteMap
Reusable Software
Structured Programming
Eco Simulation
«Prev
Reusable Code
Polymorphism Concept
Comparing Conversion Operators
ADT Conversion
Conversion Member Functions
Signature Matching Algorithm
Operator Overloading
Unary Binary Overloading
friend Function Usage
friend Function - Quiz
Overloading Operators
Pure Polymorphism
Define Class Inheritance
Pure Polymorphism
Derived Class
Public Inheritance
public Inheritance - Quiz
Constructors Base
Reference Typing Conversions
print member-function
Virtual Functions
Guidelines Virtual Functions
Virtual Function - Selection
Virtual Function - Exercise
Abstract Classes
Reinterpret const cast
Dynamic cast Operator
RTTI
typeid Operator
throw C++ Exception
Pure Polymorphism Conclusion
Ecological Simulation
next empty Squares - Exercise
Creating next() for empty squares
Objective:
Write a version of
next()
that determines how to fill an empty square in the simulation.
Instructions
Here are some fairly simple rules for determining how to fill an empty square:
Check if there are other foxes nearby. If there are at least two of them, fill the square with a fox.
If the square is still empty, check if there are any other rabbits nearby. If there are at least two, fill the square with a rabbit.
If the square is still empty, check if there is any grass nearby. If there is, fill the square with grass.
If the square is still empty, leave it that way.
Remember, you can use
sum
to determine how many of a particular lifeform are nearby the current square.
The code you've examined so far for the
living class
is also available in a file named living.cpp, which can be found in the compressed course download file.
Paste your code below and click the
Submit
button when you are ready to submit this exercise.
Submit