Question: #include #include #include using namespace std; class RGB { public: RGB(unsigned char red = 0, unsigned char green = 0, unsigned char blue = 0)

#include #include #include

using namespace std;

class RGB { public:

RGB(unsigned char red = 0, unsigned char green = 0, unsigned char blue = 0) : r(red), g(green), b(blue) {}

unsigned char red() { return r; }

unsigned char green() { return g; }

unsigned char blue() { return b; }

private:

unsigned char r, g, b; };

class PPMImage { public:

PPMImage(unsigned int width, unsigned int height): w(width), h(height) { pixmap = new RGB*[h]; for (unsigned int i = 0; i < w; ++i) pixmap[i] = new RGB[w]; *** please explain }

~PPMImage() { for (unsigned int i = 0; i < w; i++) delete[] pixmap[i]; **** please explain

delete[] pixmap; w = h = 0; }

void put(unsigned int y, unsigned int x, RGB rgb) { if (x > w || y > h) return;

pixmap[y][x] = rgb; }

bool printToFile(string filename) { ofstream out(filename.c_str()); if (!out) return false;

out << "P3" << endl; out << w << " " << h << endl; out << 255 << endl; **** please explain loops etc for (unsigned int i = 0; i < h; ++i) { for (unsigned int j = 0; j < w; ++j) { RGB &rgb = pixmap[i][j]; out << (int)rgb.red() << " " << (int)rgb.green() << " " << (int)rgb.blue() << endl; } }

return true; }

private:

unsigned int w, h; RGB **pixmap; };

int main() { int w = 100, h = 100; PPMImage img(w, h); ***** please explain for (int i = 0; i < h; ++i) { for (int j = 0; j < w; ++j) { RGB rgb; if (i / 10 % 2 == j / 10 % 2) rgb = RGB(255, 0, 0); else rgb = RGB(0, 0, 255);

img.put(i, j, rgb); } }

string filename = "img.ppm"; if (img.printToFile(filename)) cout << "Succesfully create image!" << endl; else cout << "Couldn't write to file '" << filename << "'..." << endl;

return 0; }*************************** Please explain program - no documentation - ppm image 100 x100 checker board 10x10 blocks thanks C++

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!