Local Maxima-2 Dimensional Array

| October 27, 2015

In urban planning, a strategic objective is to find the highest peak in a terrain and build on that location. A geographic map is depicted as a grid with a value in each cell representing the elevation above sea level of that location. An urban planner wants you to write a program that will read, until the end of file (LocalMax.txt), lines of input data that consist of a two dimensional array size, n n, followed by the actual integer values in each cell representing the elevation of that location in the terrain. The program will find all the local peaks and print, for each 2D array, the coordinates and value of those local peaks (grid cell). A local peak is a grid cell whose value is larger than the sum of the values found in its neighbors. Note that the interior points have 8 neighbors, edge points have 5, and corner points have only 3. For example, given the input data:
33
90 8 45
7 25 30
6 108 565 44
100 5 6 90 8 7 10 5 80 7 6 2
9 8 97 5
the output will be
For the 3 x 3 array: 90 8 45
7 25 30
6 108 565
the local maxima are: 90 at 0,0 565 at 2,2
For the 4 x 4 array: 100 5 6 90
8 7 10 5 80 7 6 2 9 8 97 5
the local maxima are: 100 at 0,0
90 at 0,3
80 at 2,0
97 at 3,2
Here are code fragments to get you started:
// global declarations so we don’t need to be passing them in and out of functions
constint MAXROW=12, MAXCOL=12; // Assume max row size and column size do not exceed 12
ifstreaminData;
//Function readMatrix() reads the input information for the matrix (2D Array) void readMatrix(int&row, int&col, int matrix[][MAXCOL])
{
inData>> row >> col;
for (int r=0; r > matrix[r][c];
} //end of inner loop }//end of outer loop
return; }
//Function to output the matrix
void outMatrix (int row, int col, intmatrix[][MAXCOL]) {
//output the matrix
cout<< "For the " << row<< " x "< sum){
//we found a local max!
cout<< matrix[r][c] << " at } }//end of inner loop }//end of outer loop } int main(intargc, char *argv[]) { string inString; int matrix[MAXROW][MAXCOL]; introwSize, colSize; int sum; " <

Get a 5 % discount on an order above $ 150
Use the following coupon code :
2020Discount
computing environment
assignmen

Category: Homework Help

Our Services:
Order a customized paper today!
Open chat
Hello, we are here to help with your assignments