# include # include using namespace std; int main ( ) // // MONA is a "partial" program which the student is to complete. // It reads a PGM graphics file containing COLS x ROWS pixel values, // which are actually integers between 0 and 255. // // The program should be run with commands like: // // g++ mona.cpp // mv a.out mona // ./mona < mona.pgm // // The program should be completed so that it counts the number of pixels // in the 16 ranges 0 to 15, 16 to 31, 32 to 47, ..., 240 to 255, // and prints these results out. // // The results should confirm that the image is rather dark (most of the // pixel values are closer to 0 (black) than 255 (white). // { char c1, c2; int c, cols, g, g_max, r, rows; // // 1) Your declarations and initializations go here! // --------------------------------------------- // DECLARATIONS and INITIALIZATIONS // // This part of the code reads some initial data from the graphics file. // cin >> c1; cin >> c2; cin >> cols; cin >> rows; cin >> g_max; // // This part of the code reads ROWS * COLS values of G, the // amount of gray in each pixel. // for ( r = 0; r < rows; r++ ) { for ( c = 0; c < cols; c++ ) { cin >> g; // // 2) Update the appropriate counter based on the value of G // ------------------------------------------------------ // // G is a gray scale value between 0 and 255. // // We have 16 counters, each for a range of 16 values. // // Update the appropriate counter: // // COUNT[0]: 0 <= G < 16 // COUNT[1]: 16 <= G < 32 // ... // COUNT[15]: 240 <= G < 256 // // You could use 16 IF/ELSE statements, but there's a simple formula // that will tell you immediately which counter should be updated. // DETERMINE THE INDEX OF THE COUNTER TO UPDATE. UPDATE THAT COUNTER. } } // // 3) Print out your counter values here! // ---------------------------------- // PRINT THE COUNTERS. return 0; }