CPlusOOP
SiteMap
Reusable Software
Structured Programming
Eco Simulation
«Prev
Reusable Code
Polymorphism Concept
Define Polymorphism Concept
Difference Conversion Overloading
ADT Conversion
Conversion Member Functions
Comparing Conversion Operators
Compiler Selects Overloaded Function
Signature Matching Algorithm
Selection Algorithm Function Overloading
Overloaded Function Example
Using Polymorphism Conclusion
Operator Overloading
Overload Operators
Overloadable Operator Types
Declare Friend Function
friend Function Usage
Operator Keyword
Unary Binary Operator Overloading
Overloading Unary Operators
Overloading Binary Operators
Overloading Assignment Operator
Input Output Operators
Overloading Output Operator
Overloading Input Operator
Overloading Pointer Operator
Overloading New Delete
Operator Overloading Guidelines
Overloading Operators Summary
friend Function - Quiz
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