Lecture 3
Today: Hands-on lab, array applications and preparation for Hw2
Pre-lab reading: Game of Life handout.
The goal of this lab is:
- to get you up to speed with two-dimensional
array manipulation and structured program development using functions,
in preparation for Hw2.
- to see how much you can do in 2 hours and a half, working under time
pressure.
- to encourage you to think about getting organized, so that by the
end of the class you have submitted a program that compiles and
implements a minimal functionality, together with a typescript.
- to review arrays, for loops, switch statements, in the context of C++.
To do
Write C++ functions for (as many as you can of) the following tasks:
- Read a game of Life configuration from user input.
- Print a Life configuration on the standard output.
To test this functions, you will write a main program which asks the
user what to do, then depending on the choice, will execute one of the
preceeding functions or quit. The options should be:
- 1
to enter a Life configuration
- 2 to print the stored
Life configuration.
Read below the specifications on how the input/output should be formatted.
Hint: start by writing the main program and provide empty functions
for the 2 desired ones. Then implement each function, one by one, in
the logical order which will allow you to test them.
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
example,
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 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.
Your program
should read the input from user input, but for testing you can
pipe in any of these data files.
Submitting
You should develop your program in stages, keep intermediate versions and
submit the latest working version in Lab3,
before leaving the lab at 11:50. Name the file lab3.cpp and
submit a typescript, too.
You should comment your program, write on it your name
and relax: the lab will not be harshly graded. I want
to see what each of you can do when working under time pressure.
After the lab: you can continue working and thinking about ways of
completing this lab, but do not submit
anything. You continue in the next lab, when again, you will be
doing all the work in a limited amount of time and submit it by the end of the day.