Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

My loop is not iterating and storing properly. include #include #include #define ROWS 5 #define COLS 6 void calcSums(int topog[ROWS][COLS], int sumList[ROWS] ); int main()

image text in transcribed

image text in transcribed

My loop is not iterating and storing properly.

include #include #include #define ROWS 5 #define COLS 6 void calcSums(int topog[ROWS][COLS], int sumList[ROWS] ); int main() { int topography[ROWS][COLS] = { { 3011, 2800, 2852, 2808, 2791, 2818 }, { 2972, 2937, 2886, 2860, 2830, 2748 }, { 2937, 2959, 2913, 2864, 2791, 2742 }, { 2999, 2888, 2986, 2910, 2821, 2754 }, { 2909, 3816, 2893, 2997, 2962, 2798 } }; int sumList[ROWS] = {0}; int r,c; /* student to implement calcSums */ calcSums(topography, sumList ); //pass in topography, get back list of elevation sums

for(r=0; r

return 0; } /* * Receives 2d matrix that represents topography * and uses this data to calculate an elevation path sum for each * row. * Input: topog[][] * Output: sum[] * */ void calcSums(int topog[ROWS][COLS], int sums[ROWS] ) { int i,j; for( i=0; i

int sum = abs(topog[i][j]- topog[i][j+1]); int sum2 = abs(topog[i][j]- topog[i-1][j+1]); int sum3 = abs(topog[i][j]-topog[i+1][j+1]);

if (sum

}}

sums[i];//place sums in this array. One sum per row

}

page 1 of 4 Math 230 Project I: Mountain Hike Path In this lab you will read a set of topographic (land elevation) data from a 2D array and write a function to compute the path(s) through the mountains. Background: There are many contexts in which you want to know the most efficient way to travel over land. When traveling through mountains (let's say you're walking) perhaps you want to take the route that requires the least total change in elevation with each step you take - call it the path of least resistance. Given some topographic data it should be possible to calculate a "greedy lowest-elevation-change walk from one side of a map to the other. A Greedy Walk A "greedy" algorithm is one in which, in the face of 011 2900 2852 208 2791 2818 too many possible choices, you make a choice that seems best at that moment. For the maps we are dealing with there are many possible paths you could 2972 2937 2886 2860 2830 2748 take starting from the "western" side of the map and 2937 2959 2913 2864 2791 2742 taking one step forward until you reach the "eastern" side. 2909 2816 289 2997 2962 2798 Since our map is in a 2D grid, we can envision a walk" as starting in some in some cell at the left-most Shows a portion of the data. edge of the map (column 0) and proceeding forward Greedy path shown in green. by taking a "step" into one of the 3 adjacent cells in the next column over (column I). Our "greedy walk" will assume that you will choose the cell whose elevation is closest to the elevation of the cell you're standing in. (NOTE: this might mean walking uphill or downhill). The overall sum of the changes will be calculated by taking the absolute value of the sum of the changes. Since your code does not know which of the 5 rows will yield the best result, you will calculate 5 sums and en select the smallest value as the best answer. Your program should return the index of each row, and the associated best-sum for that row. page 2 of The diagrams below show a few scenarios for cho the case of a tie with the forward position, you should always choose to go straight forward. In the case of a tie between the two non-forward locations, you should flip a osing where to take the next step. In o choose where to go. That means you will need to use rand0 to make a decision for ties. elew elev change dev changs 109 9 00 07 7 05 5 109 9 100 97 3 105 5 96 4 100 973 100 os 05 5 04 4 Case I: smallest change is 5, go fwd- change is 3, go down Case 2: smallest Case 3: smallest change is a tie (3), fwd is an option, so go fwd Case 4: smallest change is a tie (4), choose randomly between fwd- up or fwd-down fwd 3011 28002 2972 2886 2860 2830 2937 2959 31302964 2791 : 2742 2999 2888 2986 2909 3816 2893 2997 29 2852 2808 2791 2818 2910 2821 2754 Cost 7+243 317

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Next Generation Databases NoSQLand Big Data

Authors: Guy Harrison

1st Edition

1484213300, 978-1484213308

More Books

Students also viewed these Databases questions