# include # include using namespace std; int main ( ) // // MONA_2D reads data from a PGM graphics file of the Mona Lisa. // We know in advance that the data consists of 360 rows and 250 columns // of integers between 0 and 255. // // The program should be run with commands like: // // g++ mona_2d.cpp // mv a.out mona_2d // ./mona_2d < mona.pgm // // The program doesn't do anything more than read that data. The user // will want to add statements that modify the data, and perhaps write // it back out as a new PGM file. // { char c1, c2; int cols, g_max, i, j, p_num, rows; int mona[360][250]; // // This part of the code reads some initial data from the graphics file. // cin >> c1; cin >> c2; cin >> cols; cin >> rows; cin >> g_max; // // Read the pixel data into the 2D array. // p_num = 0; for ( i = 0; i < rows; i++ ) { for ( j = 0; j < cols; j++ ) { cin >> mona[i][j]; p_num = p_num + 1; } } cout << "\n"; cout << "Read " << p_num << " pixels from the file.\n"; return 0; }