Thursday February 5, 2002
Due Wednesday 2/11/2000 by midnight.
Your task is to write in C++ a program for the game of Life. The program
should be named life.cpp. All the functions and the main program should
be in this file, you shouldn't use other files. You will submit in Hw2
two files, life.cpp and a typescript named typeLife.
The game of Life, and a structured approach for writing a program for it,
is contained in the handout distributed in class on Th., Jan. 31. The
description in the handout is both in pseudo-code and C. Using it to
guide your thinking, you will have to develop a full C++ program. You should
generously use functions, as suggested by the approach in the handout.
You should use the work you did in this week's labs,
lecture 3 and
lecture 4 and
build upon them (i.e. you could and should use some of the functions developed
during the labs, for the homework).
Input/Output format and Testing
To enter a Life configuration, use x's for live cells and dots
'.' for dead cells. Finish a line with a sharp sign #
and the whole configuration with an equal sign =. For
this data set corresponds to the
first example in your handout.
To simplify the testing, I have prepared a larger
set of data files
containing the data sets in Fig. 1.1 of the handout. You can copy
them directly from the web:
- Open the data file in Netscape
- From the File menu, choose Save As.
- Save on the Desktop or on the network of your computer (if you are in Windows),
then transfer the files (using ssh) to your 112b-xx account; or, if you are
under Linux, save directly in the appropriate directory
(e.g. Hw2) in your class account.
should read the input from user input, but for testing you can
pipe in any of these data files.
When testing your program, you can use the
Game of Life applet to check the accuracy of the
obtained configuration after each generation. However, be
careful: the data sets I have given you are on a small grid. I
expect your program to check when it reaches the boundary of the
When preparing the typescript, make sure
these tests show up in the given order (i.e. data01, data02, etc.).