Lecture4-2 - 1 Data Structures CSCI 132, Spring 2012...

Info iconThis preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 1 Data Structures CSCI 132, Spring 2012 Lecture 4 Implementing Life 2 Rules of Life The neighbors of a given cell are the eight cells that touch it. Every cell is either living or dead. A living cell stays alive in the next generation if it has either 2 or 3 living neighbors; otherwise it dies (of loneliness or overcrowding) A dead cell becomes alive in the next generation if it has exactly 3 neighboring cells that are already alive. All births and deaths take place at exactly the same time for each generation. 3 Specifications We want the program to: List instructions Allow user to initialize grid Print out grid at each generation Update next generation Repeat until user says stop 4 Design Class (noun) The Life game itself Methods or functions Print instructions Initialize Print Update 5 The Client Code #include "utility.h" #include "life.h" int main( ) { Life configuration; instructions( ); configuration.initialize( ); configuration.print( ); cout << " Continue viewing new generations? "<<endl; while (user_says_yes( )) { configuration.update( ); configuration.print( ); cout << " Continue viewing new generations? "<<endl; } } 6...
View Full Document

Page1 / 16

Lecture4-2 - 1 Data Structures CSCI 132, Spring 2012...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online