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

I am having trouble getting it to compile the directions and my written script i

ID: 3640059 • Letter: I

Question

I am having trouble getting it to compile
the directions and my written script is below:
if someone could give me guidelines or point me in the right direction that would be helpful!


1. 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.
( Read the first two integers from the array to get the number of rows and the number of columns in the array.
© 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, icol] and its eight neighbors form a 3 × 3 array:
? M[i-1,j-1] M[i-1,j] M[i-1,j+1] ? ? M[i, j - 1] M[i, j] M[i, j + 1] ? . ? M[i+1,j-1] M[i+1,j] M[i+1,j+1] ?
The average of these nine elements is their sum divided by 9. Function average() returns this average.
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:
1 2 3
4 5
6 7
foreach element (i,j) of array A do if (i,j) is the first or last row or column containing input data then
B[i, j] ? A[i, j]; else
B[i, j] ? the average of A[i, j] and its eight neighbors; end
end
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.
( Print a message on the terminal:
Creating file: out.data
© 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.

I wrote

#include<iostream>
#include<cstdlib>
#include<fstream>
#include<string>
using namespace std;

// FUNCTION PROTOTYPE FOR input_array()
void input_array(double array[], int row, int col)
// Three input parameters:array, row, and col
// Represents the array and integer variable for number of rows and columns
// Parameters are passed by value
{
string filename;
ifstream ifile;
int MAX_NUM_ROWS[100];
int MAX_NUM_COLS[100];

ifile.open(filename.c_str());

if(!ifile.is_open())
{
cerr<<"Unable to open file "<<filename<<endl;
exit(10);
}
cin>>array[1,2];

if(row>MAX_NUM_ROWS || col>MAX_NUM_COLS)
{
cerr<<"Error"<<endl;
exit(10);
}
ifile.close();
}
)
average(M[][],int irow, int jcol)
// Three input parameters:M[][], irow, and jcol
// Represents a 2D array and row and column numbers
// Parameters are passed by value
{
int numRow(0); //Number of input rows
int numCol(0); //Number of input columns
int length(0); //Length of array
int sum(0); //Sum of array
length(M[][])=length(array[MAX_NUM_ROWS][MAX_NUM_COLS];

for(int irow, irow<numRow-1, irow++)
{
for(int icol, icol<numCol-1, icol++)
{
sum(M[irow][jcol])=M[irow-1][jcol-1]+M[irow-1][jcol]+M[irow-1][jcol+1]+M[irow][jcol-1]+M[irow][jcol]+M[irow][jcol+1]+M[irow+1][j
col-1]+M[irow-1][jcol]+M[irow+1][jcol+1];
}
}

average=sum(array_M[irow][jcol]/9;

return(average);
}

// FUNCTION PROTOTYPE FOR smooth()
smooth(A[100][100],int numRows, int numCols, B[100][100])
// Three input parameters:A[][], numRows, numCols, and B
// A and B represent 2D arrays and numRows and numCols are number of rows and columbs in A
// Parameters are passed by value
{
int i(0); //Represents element in row
int j(0); //Representes element in column

for(int el(i,j),el(i,j)<A(i,j),el++)
if(

// FUNCTION PROTOTYPE FOR output()
output(filename)
// One input parameter:filename
// Represents output name
// Parameter is passed by value
{
int r(0); //Number of rows
int c(0); //Number of columns
filename=out.data;
ifile.open(out.data.c_str())

if(!ifile.is_open())
{
cerr<<"Unable to open file "<<filename<<endl;
exit(10);
}
cout<<"Creating file: out.data";
fout<<numRows<<numCols;
fout<<B[][];

ifile.close();
}


int main()
{
ifstream ifile;
ofstream ofile;
string filename;
int read[100][100];
int column, row;
int MAX_NUM_ROWS=100 ,MAX_NUM_COLS=100;

cout<<"Please enter input file name: "<<endl;
cin>>filename;
ifile.open(filename.c_str());

if(!ifile.is_open())
{
cerr<<"Unable to open file "<<filename<<endl;
exit(10);
}
else
{
print(filename);
}

}
// FUNCTION PROTOTYPE FOR void input_array,average,smooth,ouput,

void input_array(double array[], int row, int col);
average(M[][],int irow, int jcol);
smooth(A[100][100],int numRows, int numCols, B[100][100]);
output(filename);

Explanation / Answer

#include #include #include #include using namespace std; // FUNCTION PROTOTYPE FOR input_array() void input_array(double array[], int row, int col) // Three input parameters:array, row, and col // Represents the array and integer variable for number of rows and columns // Parameters are passed by value { string filename; ifstream ifile; int MAX_NUM_ROWS[100]; int MAX_NUM_COLS[100]; ifile.open(filename.c_str()); if(!ifile.is_open()) { cerr