General instructions: The job of the Main function is to call user-defined funct
ID: 3574219 • Letter: G
Question
General instructions: The job of the Main function is to call user-defined functions. Apply “divide and conquer” principle. Initialize elevation data in a 2 dimensional array.
it is a repost question but i miss to write the general instructions. urgent pls. THANKS.
Problem Solving Applied: Terrain Navigation Terrain navigation is a key component in the design of robotic spacecraft. Robotic spacecraft refers to spacecraft with no humans on board. These spacecraft can travel on land, such as the Mars Exploration Rovers, or above land as in the Mars Reconnaissance Orbiter. A robotic spacecraft contains numerous onboard computers that store terrain information for the area in which it is to be operated. By knowing at any time where it is (perhaps with the aid of a global positioning system [GPS] receiver, the vehicle can then select the best path to get to a designated spot. If the destination changes, the vehicle can refer to its internal maps to recompute the new path. The computer software that guides these vehicles must be tested over a variety of land formations and topologies. Elevation information for large grids of land is available in computer databases. One way of measuring the "difficulty" of a land grid with respect toExplanation / Answer
#include <fstream>
#include <iostream>
using namespace std;
int main () {
int in;
ifstream infile; // open a file in read mode.
infile.open("grid1.dat");
infile >> in; // to read data from file
int rows=in; //first value is number of rows
if(rows>25)// since maximum row size is 25 the program terminates if row size greater than 25
return 0;
infile >> in;//second value is number of columns
int col=in;
if (col>25)//since maximum column size is 25 the program terminates if column size greater than 25
return 0;
int a[rows][col];//array that represents grid
for(int i=0;i<rows;i++)// reading all the values for the grid from file
{
for(int j=0;j<col;j++)
{
infile >> in;
a[i][j]=in;
}
}
infile.close();// close the opened file.
for(i=1;i<rows-1;i++)//loop to check for all the values of grid except for the values at the boundaries as we dont
//know the peak values of them for all the four sides
{
for(j=1;j<col-1;j++)
{
if(a[i][j]>a[i-1][j]&&a[i][j]>a[i+1][j]&&a[i][j]>a[i][j-1]&&a[i][j]>a[i][j+1])// to check whether the particular
//value is greater than all its four neighbours
{
cout<<"peak at row: "<<i<<" column: "<<j<<" " //print the peak position
}
}
}
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.