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

#include <cstdlib> #include <iostream> #include <fstream> #include <string> usin

ID: 3620719 • Letter: #

Question

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

int main(int argc, char *argv[])
{
void ReadMatrix(float [][25], int*, int*);
void PrintMatrix(float [][25], int, int);
void PrintMatrixTranspose(float [][25], int, int);

{
float matrix[25][25];
int numrows, numcols;

ReadMatrix(matrix, &numrows, &numcols);
PrintMatrix(matrix, numrows, numcols);
PrintMatrixTranspose(matrix, numrows, numcols);

system("pause");

}

void ReadMatrix(float matrix[][25], int*numrows, int*numcols)

{
fstream nameFile;
string filename;


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

if(nameFile.fail())
{
cout << "File name error..." <<endl;
}

nameFile >> (*numrows) >> (*numcols);
for (int i=0; i<*numrows; i++)
for (int j=0; j<*numcols; j++)
nameFile >> matrix[i][j];

}
for (int i=0; i<numrows; i++)
{
for (int j=0; j<numcols; j++)
cout << matrix[i][j] << " ";
cout << " ";
}

}







system("PAUSE");
return EXIT_SUCCESS;
}

Explanation / Answer

You have a large number of errors in your program. I have fixed and commented a number of them so that your program compiles. You will need to finish implementation of your project. I would really recommend studying your book more and adding brackets around your loops to make the code easier to read and debug. In addition I would recommend sticking to a standard naming convention for your variable names. #include #include #include #include using namespace std; // These need to be outside of main void ReadMatrix(float [][25], int*, int*); void PrintMatrix(float [][25], int, int); void PrintMatrixTranspose(float [][25], int, int); int main(int argc, char *argv[]) { float matrix[25][25]; int numrows, numcols; ReadMatrix(matrix, &numrows, &numcols); PrintMatrix(matrix, numrows, numcols); // Needs to be defined before using PrintMatrixTranspose(matrix, numrows, numcols); // Needs to be defined before using system("pause"); return (0); // Main returns 0 on success } void ReadMatrix(float matrix[][25], int*numrows, int*numcols) { fstream namefile; // nameFile is case sensitive string filename; cout (*numcols); for (int i=0; i matrix[i][j]; } } for (int i=0; i