Question
C++ Help Program Flow Your program starts by executing the first 3 steps from Part 1: Read the data into a 2D vector Find min
C++ Help
Program Flow
Your program starts by executing the first 3 steps from Part 1:
-
Read the data into a 2D vector
-
Find min and max elevation to correspond to darkest and brightest color, respectively
-
Compute the shade of gray for each cell in the map using shade of gray = 255* (elevation point - min) / (max - min )
-
Create three parallel vectors and insert the shade of gray into all three vectors
-
-
Step 4: Compute a greedy path
Write a function that calculates distance of the path created for a starting row and colors that path a particular color.
For a row, you color the cell you are at using the RGB color value passed in as three int parameters to the function, and compute your next position (following the specified movement rules) and color it, until you get to the last column. To choose the direction to move at each step, you look at the elevation data (that you read from a file) and compute the difference. Remember that you can be going downhill or uphill, therefore when you compute your vertical movement/distance, notice that it may end up negative, and you will need to compare the absolute value of vertical differences. As you color the path, you also have to compute the total distance. This is used to identify the best among all the greedy paths. You will need to return this distance at the end of the function.
The function will compute the greedy path starting at the given row and color it with the provided RGB color value, returning the total vertical movement. Every step you take should follow the greedy choice strategy we described (including what to do when there are ties.) As you move through the path, keep a running total of the total elevation change that would be 'experienced' by a person walking this path. Since we consider an elevation change the absolute value (i.e. going 'uphill' 10 meters is the same amount of change as going 'downhill' 10 meters), this running total will be non-decreasing and may end up being a pretty large positive number. The function should return this running total, so that you can compare it with other totals.
Greedy Function Requirements
-
The function declaration and definition should be placed in separate header and source files named functions.h and functions.cpp. You may place other functions there as well.
-
The function signature/prototype is:
-
You do not need to add any parameters. Note you can use a vectors size() function to determine how many elements it has. So no need to add any extra parameters.
-
int colorPath(const vector
-
1st parameter is the 2d vector of elevation data
-
2nd parameter is 2d vector of red values for an RGB color for the corresponding row,col location in the elevation data
-
3rd parameter is 2d vector of green values for an RGB color for the corresponding row,col location in the elevation data
-
4th parameter is 2d vector of blue values for an RGB color for the corresponding row,col location in the elevation data
-
5th parameter is the red value for the RGB path color. This color will replace the grey color of corresponding row,col locations of the pathn
-
6th parameter is the green value for the RGB path color. This color will replace the grey color of corresponding row,col locations of the path
-
7th parameter is the blue value for the RGB path color. This color will replace the grey color of corresponding row,col locations of the path
-
8th parameter is index of the starting row to begin procedure on.
-
Returns the distance of the path. This is the sum of changes in elevation from one column to the next.
-
Step 5: Call Function
Call the greedy algorithm function ( colorPath()) for each row (a loop works well). The greedy path should start on the west edge of the row (i.e. index 0) and color in red [RGB(252,25,63)] the corresponding cells in your output RGB data. While executing the loop, keep track of which row has the shortest path. If more than one path is shortest, then use the one with the lowest index.
-
Step 6: Paint shortest path
Call the function again for the row with the shortest path using this green [RGB(31,253,13)] for the color.
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