CSC 161 Schedule Readings Labs & Projects Homework Deadlines Resources

Proximity to Electrical Service

Architectural plans for a building often show the location of electrical outlets. In this problem, a program reviews the minimum distances from room locations to electrical outlets throughout the building.

Because walls are often constructed with 2"×4" studs, consider placing the floor plan of a building on a 4" grid. A sample floor plan is shown below for a 25' by 15' structure (grid size 76×46) (where the numbers show distance in feet):

                                  1  1  1  1  1  1  1  1  1  1  2  2  2  2  2  2
    0  1  2  3  4  5  6  7  8  9  0  1  2  3  4  5  6  7  8  9  0  1  2  3  4  5
 0  wwwwwwwwwwwwwwwwwvwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwvwwwwwwwwwwwwwwwwwwwww
    w                                w                                         w
    w                                w                                         w
 1  w                                w                                         w
    w                                w                                         w
    .                                w                                         w
 2  .                                =                                         <
    .                                w                                         w
    .                                w                                         w
 3  .                                w                                         w
    .                                w                                         w
    .                                .                                         w
 4  .                                .                                         w
    .                                .                                         w
    .                                .                                         w
 5  .                                .                                         w
    .                                .                                         <
    .                                .                                         w
 6  w                                .                                         w
    w                                .                                         w
    w                                .                                         w
 7  w                                .                                         w
    w                          f     w                                         w
    w                                w                                         w
 8  wwwwwwwwwwwwww|wwwwwwwwwwwwwwwwwwwwwwww.............www|wwwwwwwwwwwwwwwwwwww
    w                                                                          w
    w                                                                          w
 9  w                          f                                               <
    w                                                                          w
    w                                                                          w
10  w                                                                          .
    w                                                                          .
    w                                                                          .
11  w                                                                          .
    w                                                                          .
    >                                                                          .
12  w                                                                          .
    w                                                                          .
    w                                                                          .
13  w                                                                          .
    w                                                                          .
    w                                                                          w
14  w                                                                          w
    w                                                               f          w
    w                                                                          w
15  wwwwwwwwwww^wwwwwwwwwwwwwwwwwwwwwwwwww^wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww

This floor plan uses a simple notation for these main elements:

In the example, the left wall has two electrical outlets accessible to the room on the right, the right wall has two outlets accessible to the left, and the middle wall has one location where outlets are available on both the left and right. Similarly the wall at the top has two outlets available to the rooms at the top, the wall at the bottom as two outlets available to the room above, and the middle wall has two locations with outlets available to the rooms on both sides.

Although this representation is reasonably primitive, it translates simply to a 2-dimensional character array. Pragmatically, this should be set up by first asking the user for the size of the grid and then entering the character codes row by row.

Write a program that reads the grid and then reads positions in the grid. For each position read, the program should compute the approximate shortest distance (in inches) to an electrical outlet.

Programming notes: