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

Write a program to read in a two dimensional array from a file, creates a copy o

ID: 3626570 • Letter: W

Question


Write a program to read in a two dimensional array from a file, creates a
copy of the input array, and write the copy to a file “out.data”. Compute
array values by computing the average of each array value and its 8
neighbors.
program algorithm
Declare global constant variables MAX_NUM_ROWS and MAX_NUM_COLS,
each set to the value 100. The input array must have fewer than MAX_NUM_ROWS rows and fewer than MAX_NUM_COLS columns.
2. In the main program, declare two 2D arrays of size MAX_NUM_ROWS x
MAX_NUM_COLS whose values are double precision floating point numbers.
Your data will be read into one of these arrays. You will store the smooth values
in the other array.

3. Prompt and read the input file name.
4. Call a function to read the input array from the input file as follows:
(a) Open an input file stream with the given input file name. If opening the file stream
fails, print an error message and exit.
(b) Read the first two integers from the array to get the number of rows and the
number of columns in the array.

(c) If the number of rows is greater than MAX_NUM_ROWS or the number of
columns is greater than MAX_NUM_COLS print an error message and exit.

(d) If the read fails because there is non-numeric data in the file, print an error
message and exit.

(e) Close the input file stream.
Parameters to the read function should be:
? A two dimensional array of size MAX_NUM_ROWS x MAX_NUM_COLS
whose values are double precision floating point numbers;

? An integer variable for the number of rows;
? An integer variable for the number of columns.
Note that the variables for the number of rows and number of columns are set
inside the function.
5. Write a function average which computes the average of a value in an array and
its 8 neighbors. Parameters to the function are:

? A two dimensional array M of size MAX_NUM_ROWS x
MAX_NUM_COLS whose values are double precision floating point
numbers;

? A row number irow where 0 < irow < numRow - 1;
? A column number jcol where 0 < jcol < numCol - 1.

numRow and numCol are the number of input rows and columns, respectively.
The conditions on irow and jcol ensure that irow and jcol have eight neighbors in
the input array.
M [irow, jcol] and its eight neighbors form a 3 x 3 array:
The average of these nine elements is their sum divided by 9. Function average()
returns this average.
Function average() does not modify array M.

6. Call a function which takes two arrays A and B and sets the values of B to be
smoothed versions of the values of A. Parameters to the function are:
? A two dimensional array A of size MAX_NUM_ROWS x
MAX_NUM_COLS whose values are double precision floating point
numbers;

? An integer variable numRows for the number of rows in A containing input
data;

? An integer variable numCols for the number of columns in A containing input
data;

? A two dimensional array B of size MAX_NUM_ROWS x
MAX_NUM_COLS whose values are double precision floating point
numbers.

Copy smoothed values of array A into array B, as follows:
7. Call a function to output data to the output file as follows:
(a) Open an output file stream with the output file name “out.data”. If opening the
file stream fails, print an error message and exit.
(b) Print a message on the terminal:
Creating file: out.data

(c) Write the number of rows and number of columns to the output file.
(d) Write each element of the array B to the output file;

(e) Each value should be printed as fixed precision with two digits after the
decimal point. Numbers in each column should be aligned so that their
decimal points line up. You may assume that all numbers are strictly greater
than -100 and strictly less than 100.

(f) Close the output file stream.
Note that the sample executable smooth_solution.exe writes its output to the file
“outS.data” which has a slightly different file name.

Explanation / Answer

#include #include #include using namespace std; void main() { ifstream ifile; ofstream ofile; string filename; int read[100][100]; int column, row; int max_c=100,max_r=100; coutmax_c) cout
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