Laboratory 2
Due at the beginning of class, Wednesday, 2/5
In today's lab you will get some practice debugging a program and working with objects in C++. In addition, we will work with some data hiding. In lecture you were introduced to the Life Class to play the game of life. The lectures and the book together presented the implementation of the life class.
The code that was presented in class and in the book is available in the directory:
Start the lab as follows:
There are several errors of each type in the code you have copied over to your directory. Fix each of the errors (but keep track of each one as you fix it). To compile the program use the compile command:
When the program is running correctly, print out a copy of each of the three files and circle the places where there were errors. Write a short comment on the printout indicating what the error was, and whether it generated a syntax error or a runtime error. On a separate sheet, list all the errors you found. To test for the runtime errors, test your code on the following three in a row input pattern:
Which is generated with the following coordinates:
An alternative way to deal with the edges of the board is to "wrap around" when counting neighbors. The term "wrap around" means that the left side will be connected to (neighboring) the right side and the top will be connected to the bottom. Thus any cell with position (1, col), will have a neighbor at (maxRow, col). Any cell with position (row, 1) will have a neighbor at (row, maxCol).
So a cell at position (3, 1), will have the following neighbors:
Your task is to rewrite life.h and life.cc so that the board uses the wrap-around method to deal with edges. Be careful about the corners! Specifically you will need to change the following:
Test your program on the following:
Configuration 2:
1 60
2 60
3 60
-1 -1
Can you think of other configurations that should be tested? Do so!
What To Turn In.
~csci132/bin/submit csci132 lab2
Be sure that the program prologue for each file contains your name, course, lecture section, date and purpose of the program or a description of the contents of the file (e.g. specification of the Life class).
Reminder.
Be sure to save a copy of each file in your labs directory. It is your responsibility
to keep the copies of all programs written for this course until your
graded assignment is returned.
Home | | Syllabus | | Assignments | | Lecture Notes