19.12.2012 Views

Computer Programming Concepts and Visual Basic David I. Schneider

Computer Programming Concepts and Visual Basic David I. Schneider

Computer Programming Concepts and Visual Basic David I. Schneider

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Section 6 <strong>Programming</strong> Projects 213<br />

(b) An individual dies if he has more than three individuals or less than two in<br />

neighboring squares.<br />

(c) A new individual is born into each empty square with exactly three individuals<br />

as neighbors.<br />

Figure 6-16(b) shows the status after one generation. Write a program to do the<br />

following:<br />

(a) Dimension an n-by-n array, where n is input by the user, to hold the status<br />

of each square in the current generation. To specify the initial configuration,<br />

have the user input each row as a string of length n, <strong>and</strong> break the row into<br />

1’s or dashes with Mid.<br />

(b) Dimension an n-by-n array to hold the status of each square in the next generation.<br />

Compute the status for each square <strong>and</strong> produce the display in<br />

Figure 6-16(b). Note: The generation changes all at once. Only current cells<br />

are used to determine which cells will contain individuals in the next<br />

generation.<br />

(c) Assign the next-generation values to the current generation <strong>and</strong> repeat as<br />

often as desired.<br />

(d) Display the number of individuals in each generation.<br />

Hint: The hardest part of the program is determining the number of neighbors a cell has. In<br />

general, you must check a 3-by-3 square around the cell in question. Exceptions must be made<br />

when the cell is on the edge of the array. Don’t forget that a cell is not a neighbor of itself.<br />

(Test the program with the initial configuration shown in Figure 6-17. It is known as the figure-eight<br />

configuration <strong>and</strong> repeats after eight generations.)<br />

FIGURE 6-16 Two Generations FIGURE 6-17 The Figure Eight<br />

9. Simulate the game Concentration. The Form_Load routine should create an<br />

array of 20 comm<strong>and</strong> buttons placed vertically on a form. A list of 10 words<br />

should be r<strong>and</strong>omly assigned as potential captions for the buttons, with each<br />

word assigned to two comm<strong>and</strong> buttons. Initially, none of the buttons should<br />

show their words. However, when a button is clicked on, its word is revealed as<br />

its caption. After two words have been revealed, either both of the comm<strong>and</strong><br />

buttons should become invisible (if their words match) or their captions should<br />

again become blank (if the two words do not match). When all matches have<br />

been found, a message box should display the number of tries (pairs of words<br />

exposed) <strong>and</strong> an appropriate remark about the user’s concentration ability. Possible<br />

remarks might be, “You must have ESP” (less than 14 tries), “Amazing<br />

concentration” (14 to 20 tries), “Can’t hide anything from you” (21 to 28 tries),<br />

“Perhaps a nap would recharge your concentration” (29 to 37 tries), <strong>and</strong> “Better<br />

find a designated driver” (more than 37 tries).

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!