Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In put elevations is here Problem 1: Terrain Navigation is needed in the design

ID: 3598258 • Letter: I

Question

In put elevations is here

Problem 1:

Terrain Navigation is needed in the design of remotely piloted vehicles (RPVs). With terrain information, the RPV can select the best path to take to get to a destination, such on Mars. Knowing the ‘peaks’ in a grid of elevations can help the RPV determine a good route. A peak is defined as a point on a grid where the four elevation points adjacent on all sides are all lower. You are to write a program that reads in the data and stores it in a 7 by 7 two dimensional array. It then finds the peaks, identifies their locations and counts how many peaks there are. Also identify the highest peak. Have the user input the name of the input file to be used as a string. The input file is called elevations.txt and is on Blackboard under Assignment 7. The peaks are shown in bold to help you make sure that your program is correct.

Create an output file for this program. Output should appear as follows (no bold):

542.2 543.3 542.3 543.1 544.1 543.6 543.4 543.1 543.4 546.1 545.8 546.8 547.2 547.3 544.1 544.3 547.1 546.9 548.9 547.5 547.7 544.6 545.5 545.6 547.6 546.7 546.3 545.4 543.2 543.9 544.5 547.6 546.5 545.9 544.2 543.4 544.6 545.7 544.9 544.8 543.9 543.3 543.2 544.2 544.8 544.4 543.8 543.1 542.6

Explanation / Answer

#include<iostream>
#include<fstream>
#include<iomanip>

using namespace std;

int main(){

   double max1,max2,max3;
   int i1,j1,i2,j2,i3,j3;
   ifstream fin;
   fin.open("elevations.txt");
   double data[7][7];

   for(int i = 0;i<7; i++){
     for(int j = 0; j<7; j++){
        fin >> data[i][j];
     }
   }
   fin.close();
   cout << "Elevation matrix is : " << endl;
   for(int i = 0;i<7; i++){
     for(int j = 0; j<7; j++){
        cout << data[i][j] << " ";
     }
     cout << endl;
   }
  
   max1 = data[0][0];
   for(int i = 0;i<7; i++){
     for(int j = 0; j<7; j++){
        if (max1 < data[i][j]){
           max1 = data[i][j];
           i1 = i;
           j1 = j;
           data[i][j] = 0;
        }
       
     }
   }
   max2 = data[0][0];
   for(int i = 0;i<7; i++){
     for(int j = 0; j<7; j++){
        if (max2 < data[i][j]){
           max2 = data[i][j];
           i2 = i;
           j2 = j;
           data[i][j] = 0;
        }
       
     }
   }
   max3 = data[0][0];
   for(int i = 0;i<7; i++){
     for(int j = 0; j<7; j++){
        if (max3 < data[i][j]){
           max3 = data[i][j];
           i3 = i;
           j3 = j;
           data[i][j] = 0;
        }
       
     }
   }
   cout << "The grid size is 7 by 7 ";
   cout<< "The peaks are: ";
   cout << "Elevation " << max1 << " at point " << i1 << "," << j1 << endl;
   cout << "Elevation " << max2 << " at point " << i2 << "," << j2 << endl;
   cout << "Elevation " << max3 << " at point " << i3 << "," << j3 << endl;
  
   return 0;
}