#include <iostream> #include <iomanip> using namespace std; class GrayImage; //Pre-declaration //Classes class Pixel { public: Pixel(int v, int r, int c, GrayImage * m); int getValue(); void setValue(int); void print(); private: int value; int rol; int col; GrayImage * img; }; //v: pixel value; r: row; c: column; m is a pointer to the image to which this pixel belongs. Pixel::Pixel(int v, int r, int c, GrayImage * m) { //To be completed } void Pixel::print() { cout << setw(4) << value << " "; } class GrayImage { public: GrayImage(int ** arr, int r, int c); int countWhitePixels(); void processImage(); Pixel * getPixel(int, int); int getRows(); int getCols(); void print(); private: int rows; int cols; Pixel *** pixels; //A 2D array of pointers to pixels (of type Pixel) }; //Constructor. arr is a 2D array of pixel values. r: rows; c: columns GrayImage::GrayImage(int ** arr, int r, int c) { //Create a 2D array of pointers to pixels (of type Pixel) pixels = new Pixel ** [r]; for (int i = 0; i < r; i++) pixels[i] = new Pixel * [c]; rows = r; cols = c; //Use pixel values in arr to create Pixel objects at each location //Hint: use double loops //To be completed } Pixel * GrayImage::getPixel(int r, int c) { return pixels[r][c]; } int GrayImage::countWhitePixels() { int n = 0; //The number of white pixels (i.e. 255) //To be completed return n; } void GrayImage::processImage() { //To be completed } void GrayImage::print() { cout << "\nThe pixel values of the image are: \n" << endl; for (int i = 0; i < rows; i++) { for (int j = 0; j < cols; j++) //To be completed } } int main() { //Create a 2D dynamic array int ** a; a = new int *[4]; for (int i = 0; i < 4; i++) a[i] = new int[5]; //Input pixel values to a temporary 2D array int b[4][5] = { {221, 184, 178, 84, 135}, {84, 255, 255, 130, 84}, {78, 255, 0, 0, 78}, {84, 130, 255, 130, 84} }; //Copy to the dynamic array for (int i = 0; i < 4; i++) { for (int j = 0; j < 5; j++) { a[i][j] = b[i][j]; } } GrayImage gimg(a, 4, 5); gimg.print(); cout << "\nThe number of white pixels is " << gimg.countWhitePixels() << endl; gimg.processImage(); gimg.print(); return 0; } //The pixel values of the image are: // // 221 184 178 84 135 // 84 255 255 130 84 // 78 255 0 0 78 // 84 130 255 130 84 // //The number of white pixels is 4 // //The pixel values of the image are: // // 221 184 100 84 135 // 0 125 171 130 84 // 78 255 0 0 78 // 84 130 255 130 84 //Press any key to continue . . .
Upon completion, save all programs and the required output into a single zip file. The file should be named in this format: P1_YourName.txt, for example, P1_JohnDoe.txt. Then submit to the Blackboard (Bb) as attachment by the deadline. The submission link on the Bb will be closed automatically after the deadline. Assignments that fail to follow the instructions will NOT be graded.