Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#include #include #include #include using namespace std; int main() { int height; // rows int width; // columns string file; cout < < enter the

#include #include #include #include using namespace std; int main() {

int height; // rows int width; // columns string file;

cout << "enter the height of the map you wish to analyze" << endl; cin >> height; cout << "enter the width of the map you wish to analyze" << endl; cin >> width; //cout << "enter the name of the mountain you wish to analyze" << endl; //cin >> file;

vector> altVec(height, vector(width)); ifstream myfile; myfile.open("map-input-100-100.dat");

if (!myfile.is_open()) { cout << "Could not open file myfile" << endl; system("pause"); return 1; }

for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { myfile >> altVec[i][j]; //cout << "[ " << i << "][ " << j << "] = " << altVec[i][j] << endl; }

} myfile.close();

int max = -1; int min = 10000000000;

for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { if (altVec[i][j] > max) { max = altVec[i][j]; } if (altVec[i][j] <= min) { min = altVec[i][j]; }

} } double xmin = min; double xmax = max; double xheight = height; double xwidth = width; vector> colorVec(xheight, vector(xwidth)); double x; for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { x = ((altVec[i][j] - xmin) / (xmax - xmin)) * 255; cout << x<< endl; } } cout << min<< endl; cout << max << endl; cout << altVec[50][50] << endl; system("pause"); }

So in this assignment we are supposed to take elevation readings from a 2d map in a .dat file. I was able to copy the data into my own 2d vector, calculate the max and min, and even calculating the shade of grey for each elevation point using the formula: ((exact elavation point-min)/(max-min))*255 . However I am struggling to understand this part: As you compute the shade of grey, store that value in three parallel vectors for R, G and B. Putting the same value for R, G and B will result in grey. The structure of the vector should mirror the vector with the elevation data. I have the values for shades of gret, but I do not understand whar it means to put those points into another vector. Above is my current code:

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

Database Concepts

Authors: David Kroenke, David Auer, Scott Vandenberg, Robert Yoder

8th Edition

013460153X, 978-0134601533

More Books

Students also viewed these Databases questions