Objectives: Allocate memory dynamically and utilize pointers to directly manipulate memory.

Problem: Simulation games remain a popular genre of video games and you have decided to capitalize on their success by designing SimBacteria. Given an area randomly populated by single cell organisms, players will be able to watch their cultures thrive (or die) throughout many generations of bacteria. Your program will drive the simulation and display each generation before recording the last generation into a file.

SimBacteria Rules

  • Each cell has at most 8 neighbors (cells on the edge of the world will have fewer): see image.
  • If a cell has fewer than 2 neighbors, it dies of loneliness.
  • If a cell has more than 3 neighbors, it dies from overcrowding.
  • If an empty location has exactly three neighbors, a cell is born in that location.
  • All births and deaths happen simultaneously.


  • Modular programming is required.
  • Any global variables must be constants.
  • The world in which the bacteria live is a 2 dimensional array.
  • The array will be dynamic the size of the array will be based on the initial bacteria generation.
    • You may create a dynamic multi- or single dimension array
    • Dynamic multi-dimensional arrays require double pointers
    • Remember that standard multi-dimensional arrays in C++ are stored as single dimension arrays in memory
    • This may be easier to work with than the double pointers.
  • The initial bacteria generation will be read from a file.
  • The use of pointers is required to traverse the array.
  • You must use pointer arithmetic to move the pointers.
  • The use of bracket notation to access the array is not allowed.
  • The final bacteria generation should be stored in a file.

Input: The initial bacteria generation will be read from a file named simbac.txt. Each line in the file will represent a row in the array. The array is to be no bigger than the initial bacteria generation presented in the file.

Each row will contain two types of characters - asterisks (*) or a space. An asterisk represents an organism and the space represents an empty cell. Each line of the file (except the last) will contain a newline character.

Once the file has been read into memory, prompt the user to enter the number of generations to simulate. The maximum number of generations allowed for simulation is 10. You must validate that the user only enters an integer from 1 10. If the user enters invalid data, display an error message and prompt the user for correct input.

Output: After the user has entered a valid number, display each generation to the console. The last generation should be displayed to the console as well as written to the file (simbac.txt). Use an asterisk (*) to indicate an active cell during output.


  • You should consider a second 2 dimensional array to mark births and deaths
    • This allows you to evaluate births and deaths simultaneously
  • There are 3 rows of neighbors for cells. It may be easier to check neighbors by using a pointer for each row of neighbors
    • Remember the border cases have fewer neighbors
Academic Honesty!
It is not our intention to break the school's academic policy. Projects posted are only used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly fill out the form. Please provide a valid email address and we'll get back to you in less than 24 hours. We will be sending an invoice through PayPal upon confirmation. We are a non profit organization however we need an amount to keep this organization running, and to be able to complete our research and development.