Question
#include #include #include using namespace std; class RGB { public: RGB(unsigned char red = 0, unsigned char green = 0, unsigned char blue = 0)
#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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started