Question: Please solve all my doubts (a) Using C++'s Standard Template Library vector class template, define the private data and public interface of an Image class


(a) Using C++'s Standard Template Library vector class template, define the private data and public interface of an Image class in which each pixel is a single byte (in C++ this is an unsigned char). Hint: the private data will need to store the image data itself and you could either use a vector of vectors of unsigned chars for this, or a single flat vector of unsigned chars; it will also need the height and width of the image; the interface will need methods to get and store pixel data, etc; the constructor should take the height and width as arguments and create the pixel data. (b) How could you change your class so that it could store a real number per pixel instead (i.e. double)? a 1 why use unsigned char 2 3 4 why 5 6 17 8 0 6 class Image { GI: public: Q3 : Image (int w, int h); use void? unsigned char GetPixel (int x, int y); void Set Pixel (int x, int y, unsigned char val); int GetHeight(); int GetWidth(); Q2:3 why input this? private : vector > pixels; int width; int height; 04: Why 2 sets of ca }; Image:: Image (int w, int h) : width(w), height (h) { pixels.resize(height); for (int i=0; i
Step by Step Solution
There are 3 Steps involved in it
Lets go through each part to address your questions and doubts a Define Image Class using unsigned char Why use unsigned char An unsigned char can rep... View full answer
Get step-by-step solutions from verified subject matter experts
