Problem navigation over a terrain can be an important


Elevation in 2D arrays (C++)

DATA FILE: https://pastebin.com/DTQ9kenP Goals: Using 2-dimensional arrays.

Problem: Navigation over a terrain can be an important concept. Usually you want to avoid high areas (peaks) and low areas (valleys). For this problem, you may assume the terrain that you want to navigate over may be represented as a 2-dimensional grid of cells. You are to determine the number of peaks and valleys in this terrain as well as give the location of these peaks and valley. A peak is defined as a cell for which all eight neighbors are lower than the cell being considered.

A valley is defined as a cell for which all eight neighbors are higher than the cell being considered. An example grid is given below with some of the peaks in bold and some of the valleys underlined. Note that no cell on the perimeter may be considered a peak or valley. Use a function to input the values from the file (remember the first line in the file contains the number of rows and columns respectively). Use a function to locate peaks and valleys and store the locations (row and column indices) of these peaks and valleys.

Use a function to calculate the average elevation over the entire grid and determine the maximum gradient. The gradient is the absolute difference between two adjacent cells. For example in the array given below, the cell containing 43 (row 2 and column 3) would have adjacent cell containing the values 63, 45, 38 and 40.

Design your code so you do not compare the same two cells more than once. Use a function to output the number of peaks or valleys and elevations associated with the peak or valley and the locations of these peaks or valleys (this file will be called twice from main).

Create an output file containing number of peaks, number of valleys, and locations ([row, column]) of these peaks and valleys, the average height, and maximum gradient.

Your main function should Declare the 2-Dimensional array (no input file will contain more than 100 rows and 100 columns).

Call the function to import the data

Call the function to locate the peaks, valleys, and locations of the peaks and valleys.

Call the function to calculate the average and maximum gradient.

Call the function to output peaks or valleys and locations with peak information.

Call the function to output peaks or valleys and locations with valley information.

Call the function to determine the overall elevation average and maximum gradient and output these.

Solution Preview :

Prepared by a verified Expert
Data Structure & Algorithms: Problem navigation over a terrain can be an important
Reference No:- TGS01186800

Now Priced at $30 (50% Discount)

Recommended (98%)

Rated (4.3/5)