Write a program to read in a two dimensional array from a file, creates a “smoot
ID: 3626596 • Letter: W
Question
Write a program to read in a two dimensional array from a file, creates a “smoothed”
copy of the input array, and write the “smoothed” copy to a file “out.data”. Compute
smoothed array values by computing the average of each array value and its 8
neighbors.
here is what i have
#include
#include
#include
#include
#include
using namespace std;
//Global constants
const int M_R =100;
const int M_C =100;
//read in prototype
double read_in(const double Read[M_R][M_C]);
//average prototype
double avg(const double M[M_R][M_C], int irow, int icol);
//copy Value A to B
double copy_A(const double A[M_R], int NR, int NC);
//out data
double out_d(const double out[M_R][M_C],double B[M_R][M_C], int NR, int NC );
int main()
{
double read[M_R][M_C];
double store[M_R][M_C];
string input_f;
cout<<"Please input file name";
cin >> input_f;
return 0;
}
//Function for read in
double read_in(const double Read[M_R][M_C])
{
ifstream fin;
string input_f;
int r;
int c;
cout <<"enter file name:";
cin >>input_f;
fin.open(input_f.c_str(),ios::in);
if(!fin.isopen())
{
cerr <<"Unable to open file" < exit(10);
}
for(int i=0; i <=2; i++)
{
for(int j=0; j <=2; j++)
{
fin>>r >>c;
cout << r < }
}
fin>>r,c;
while(!fin.fail())
{
cout<<"Read number of row and column:" << r << c < fin >> r >>c;
}
if(r > M_R || c > M_C)
{
cout<<"Error the number is greater than the array limit";
}
while(fin.fail)
{
cerr <<"Error reading file" < exit(20);
}
fin.close();
}
//average function
double avg(const double M[M_R][M_C],int & irow, int & jcol)
{
double sum;
double average;
for(irow=0; irow {
for(jcol=0; jcol {
sum+=M[irow][jcol];
average= sum/9.0;
}
}
return(average);
}
double copy_A(const double A[M_R][M_C], double B[M_R][M_C], int NR, int NC)
{
for(int i=0; i {
for(int j=0; j {
if(i && j == A[0][0] || i && j ==A
{
B=A;
else
{
B=avg(A);
}
}
}
}
}
}
double out_d(const double out[M_R][M_C])
{
double sumi=0.0;
double sumj=0.0;
ofstream fout;
fout.open(out.data.c_str(),ios::out);
if(!fout.is_ipen())
{
cerr<<"unable to open file out.data" < exit(10);
}
cout <<"Creating file:out.data" <
for(int i=0; i {
for(int j=0; j {
sumi+= i;
sumj+= j;
fout <<"number of rows"<< sumi <<"number of columns" << samj << endl;
fout < }
}
}
Explanation / Answer
i made the program for u from the begininng coz i found many errors in your code :) if u needed any help message me #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) coutRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.