Question: Problem Description: Stream Paths Suppose you have a 2D array elev of integers that represent elevations on a grid. If a stream of water originates


Problem Description: Stream Paths Suppose you have a 2D array elev of integers that represent elevations on a grid. If a stream of water originates at the location with row index r and column index c, what would it do what path would it take and where would it end up? This problem is similar to problems in many areas, for example, in certain optimization techniques ("steepest descent") In this problem we'll make the tollowing assumptions 1. The elevation grid will be a n row, m column grid of integers, where n and m are constant ints. (Note: the example below uses a 7-row 5-column array; however, do not "hard code" 7 and 5 in your program. Instead use n and m so it will be easy to change the sizes if needed.) 2. Once the stream origin's location is specified, then the stream flows to whichever of the four adjacent locations in the grid represents the largest descent. The adjacent locations are the locations (i) in the same column, but with row index decreased by 1, (ii) in the same row, but with column index increased by 1, (ii) in the same column, but with row index increased by 1, and (iv) in the same row, but with column index decreased by 1 3. If more than one of the adjacent locations have the largest decrease, then the water Hows to whichever adjacent location appears first in the last item's list. 4. This process continues, with the stream flowing from location to location until it either reaches a location where none of the four adjacent locations has its elevation strictly less than that location, or until it reaches the edge of the grid (any row with index 0 or n-1, or any column with index 0 or m-1 This homework asks you to solve this problem in two parts Problem A: A Single Step (20 points) Write a C++ program that sets up a grid, and then asks a user to input an initial location If the input location is an invalid location (row less than 0 or greater than or equal to n, or column less than 0 or greater than or equal to m), the program should print "Invalid location". Otherwise the program should call a function you should write
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
