Question
Hi, I need desperate help with one of my assignments and I have no clue where to start. I started the assignment (below) but then
Hi, I need desperate help with one of my assignments and I have no clue where to start. I started the assignment (below) but then got lost on what to do. Any help or direction would be greatly appreciated! Thanks ahead!
Assignment::
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.
Create a "greedy algorithm" to calculate the index of each row and the associated best-sum for that row.
It should be coded to receive a 2d array as input, calculate the elevation sums, and insert the sums into the array sumList[ ]. Main() will print out the values inserted into sumList[ ].
The objective is to use each row of the first column of the 2d array as a starting point to come up with a sum of absolute value of differences. For each row, a sum will be calculated, therefore, 5 sums must be calculated. Each sum will be placed into the array, sumList[ ].
Program::
#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
calcSums(int topog[ROWS][COLS], int sumList[ROWS] )
int index= 0;
for (int r = 0; r < topography.length; r++){
for (int c = 0; c < topography[r].length; c++) {
sumList = sumList + topography[r][c];
}
}
printf("%8d %8d ",r, sumList[r]); //should display calculated sums
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 r,c;
for( r=0; r { //placeholder. Calculate correct sums sums[r] = 99999; //place sums in this array. One sum per row } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started