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

Given that Sale NUM ROWTNUM COLUMN is a two dimensional array of float- point ty

ID: 3750994 • Letter: G

Question

Given that Sale NUM ROWTNUM COLUMN is a two dimensional array of float- point type and the two constants are defined as follows #define NUM ROW 4 #define NUM COLUMN 4 float ValuejNUM ROWINUM COLUMN- 2.1, 2.2, 2.3. 2.4 Write a C++ main function that computes and prints out the following information about this 2d array: (1) The mean of all the array elements (1.25 points) (2) The local average values of all the array elements (1.25 points). For instance, the i,j(Value- 1]0]+Value[i+1]]+Value[i]j+Valuei]j-1)/4. If (i+1) > NUM ROW-1 or (i-I)

Explanation / Answer

a) #include<iostream>

using namespace std;

void main()

{

float sum = 0.0 ; // initialize float variable sum as zero . It stores the total sum of array Value[NUM_ROW][NUM_COLUMN]

for (int i =0 ; i< NUM_ROW ; i ++) // outer for loop will iterate on rows of array

{

for ( int j =0; j< NUM_COLUMN ; j++) // inner for loop will iterate on column of array

{

sum = sum + Value[i][j] ; // this will calculate sum of all the elements of the array and store the final value in sum variable

}

}

float mean = sum / ( NUM_ROW * NUM_COLUMN ) ;

cout << " Mean of all the array elements of array Value[NUM_ROW][NUM_COLUMN] is :" << mean ;

} // end of main()

cout will print the mean of the array .

2. void main()

{

float Average[NUM_ROW][NUM_COLUMN] = {};

for (int i =0 ; i< NUM_ROW ; i ++) // outer for loop will iterate on rows of array

{

for ( int j =0; j< NUM_COLUMN ; j++) // inner for loop will iterate on column of array

{

if ( ( (i+1) > (NUM_ROW -1) ) || ( (i -1) < 0) ) // this condition will check if the row excedes the last row or is less than the first row in array "Value", if so below condition will execute

{

Average[i][j] =| ( Value[ i-1 ][ j ] + Value[ i+1 ][ j ] + Value[ i][ j+1 ] + Value[ i ] [ j-1] ) / 4 | ;

}

else

    Average[i][j] = ( Value[ i-1 ][ j ] + Value[ i+1 ][ j ] + Value[ i][ j+1 ] + Value[ i ] [ j-1] ) / 4 ;

}}

for (int m =0 ; m< NUM_ROW ; m++)

{

for ( int n =0 ; n< NUM_COLUMN ; n++ )

{

cout << "Local average value of element at Value[" << m << "][" << n << "] is " << Average [m ][ n ] << endl;

}

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote