We can consider a crossword
puzzle as a 2-dimensional array of characters. Suppose we had a crossword
puzzle like the one below with the rows and columns numbered for the person
who will do the puzzle.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
||||||||||||
|
|
||||||||||||
|
|
|
|
||||||||||
|
|
|
b | e |
|
t | l | e | |||||
|
|
|
|
|
|
|
|
|
|
r | |||
|
|
|
|
g | |||||||||
|
|
|
|
||||||||||
|
|
|
|
|
|
|
|
|
|
||||
|
|
|
|
|
|
|
|||||||
|
|
|
|
|
|
|
|||||||
|
|
|
|
|
|
||||||||
|
|
|
|
|
|
|
|
|
|
We want the program to prompt the person at the keyboard for a position, direction and word to place into the puzzle. The program should then place the word in the puzzle as shown above for the following four examples.
Enter position, direction, and word: 5
2 a argument
Enter position, direction, and word:
5 6 d maneuver
Enter position, direction, and word:
8 5 a message
Enter position, direction, and word:
9 12 d amp
Enter position, direction, and word:
4 12 d erg
Enter position, direction, and word:
12 5 a origame
Other words in the crossword were placed there by previous prompting and key input.
How can we construct a program
to do this?
Part II
37 15 6 -12 78 -7 43 . . .
16 34 -16 8 40 50 10 . . .
-4 17 19 20 -33 -2 -5 . . .
56 104 11 39 -10 55 101 . . .
77 71 -3 -11 88 62 78 . . .
. . . .
. .
. . . .
. .
How can we write a part of a C++ program that can prompt for a row and column specification from the keyboard and then display (in a 3x3 square) the nine temperatures that surround (and include) that position in the array. For example, if the specified row is 2 and the specified column is 4, the program should display the numbers surrounding temps[2][4], i.e. the -33 as; or if 3 and 1 are specified, the program should show because temps[3][1] is the 104.
8 40 50 -4 17 19
20 -33 -2 56 104 11
39 -10 55
77 71 -3
What if we prompted the person
at the keyboard for the size of the display, instead of assuming 3x3?
If we ask "Square size?" and the person enters 5, the program should display
a 5x5 square around the specified center.