Exercise #8





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.
 
 

 
1
2
3
4
5
6
7
8
9
10
11
12
1
                       
2
                       
3
         
 
   
r
     
4
         
 
 b  e
e
 t  l  e
5
 
a
r
g
u
m
e
n
t
     r
6
         
a
   
r
     g
7
         
n
   
e
     
8
       
m
e
s
s
a
g
e
 
9
         
u
   
t
 o
 r
 a
10
         
v
   
 s
 l
 a
 m
11
         
e
     
 e
 s
 p
12
       
 o
r
 i
 g
 a
 m
 e
 

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

Suppose we have a large 2-Dimensional array with int values that have been read into it;  the array actually has 250 rows and 100 columns; its name is temps because it contains temperature readings.  The display below shows a small part of the array, beginning with 37 in temps[0][0].  You may assume that all array positions are occupied.

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.