Need help with the c++ file below. Have imported this text file into array and n
ID: 3533883 • Letter: N
Question
Need help with the c++ file below. Have imported this text file into array and need to be able to return the "peak" values and their exact location in grid with a char array as well. Need help with ????? sections below.
.txt file
6,7
5039 5127 5238 5259 5248 5310 5299
5150 5392 5410 5401 5320 5820 5321
5290 5560 5490 5421 5530 5831 5210
5110 5429 5430 5411 5459 5630 5319
4920 5129 4921 5821 4722 4921 5129
5023 5129 4822 4872 4794 4862 4245
PROGRAM DESCRIPTION:
This program will use a two-dimensional array and the input file
terrain containing integer elevation data for a designated land grid
region, and will read the elevation data into the array, and then find
average elevation in the land grid, the peak elevations in the land grid,
and the grid locations of the peak elevations.
DESCRIPTION OF VARIABLES:
NAME | TYPE | DESCRIPTION
------------------------------------------------------------------
average | double | average of all elevations
elevdata | int | two-dimensional array of elevation data
sum_elev | int | summation of elevation data
rows | int | number of rows in the array
cols | int | number of columns in the array
i | int | "for" loop control variable
j | int | "for" loop control variable
column_letter | char | variable used identify columns
quit | char | variable used to quit the program
********************************************************************/
/* Preprocessor directives */
#include <stdio.h>
#include <math.h>
#define inputfile "f:\school\Engr200\terrain.txt"
/* Main function */
int main(void)
{
/* Declare and initialize variables */
int i,j,rows,cols,peak1,sum_elev=0, elevdata[6][7];
double average;
char quit, column_letter[7]={'A','B','C','D','E','F','G'};
FILE *nav;
/* Open input file */
nav = fopen(inputfile,"r");
/* Verify input file and read input data */
if(nav == NULL)
{
printf(" ERROR OPENING INPUT FILE ");
}
else
{
/* Read control numbers from input file */
fscanf(nav,"%i,%i",&rows,&cols);
/* Read elevation data into array from input file */
for (i=0; i<=rows-1; i++)
{
for(j=0; j<=cols-1; j++)
{
fscanf(nav,"%i",&elevdata[i][j]);
}
}
}
/* Print main headings to computer screen */
printf(" LAND GRID SURVEY AND ANALYSIS");
printf(" Grid Elevations");
printf(" A B C D E F G");
/* Print elevation array to computer screen */
for(i=0; i<=rows-1; i++)
{
printf(" %-4i%4i ",i+1,elevdata[i][0]);
for(j=1; j<=cols-1; j++)
{
printf(" %4i ",elevdata[i][j]);
}
}
/* Print composite information heading to computer screen */
printf(" Composite Information:");
/* Find peaks and print results to computer screen */
?????????????????????????????????????????????????????????
?????????????????????????????????????????????????????????
printf(
Explanation / Answer
-
class Int2 { -
var value : int; -
var location : int; -
function Int2 (value : int, location : int) { -
this.value = value; -
this.location = location; -
} -
} -
function Start () { -
var foo = [3, 6, 8, 33, 1, 10]; -
var max = MaxValue(foo); -
Debug.Log (max.value + " " + max.location); -
} -
function MaxValue (intArray : int[]) : Int2 { -
var max = intArray[0]; -
var location = 0; -
for (i = 1; i < intArray.Length; i++) { -
if (intArray[i] > max) { -
max = intArray[i]; -
location = i; -
} -
} -
return Int2(max, location); -
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.