Question: Need to fix and Run this program C++ //header file: #pragma once #include using namespace std; struct Pixel { int r; // [0,255] int g;

Need to fix and Run this program C++

//header file:

#pragma once #include using namespace std;

struct Pixel { int r; // [0,255] int g; int b;

};

class Image { private: Pixel image[5][4]; public: Image() { for (int row = 0; row < 5; row++) {

for (int col = 0; col < 4; col++) { image[row][col].r = 0; image[row][col].g = 0; image[row][col].b = 0; } } }

Image(int r, int g, int b) { for (int row = 0; row < 5; row++) {

for (int col = 0; col < 4; col++) { image[row][col].r = r; image[row][col].g = g; image[row][col].b = b; } } }

//func1: changeColor (int row, int col, int r, int g, int b) void changeColor(int row, int col, int r, int g, int b) { image[row][col].r = r; // set red of given pixel image[row][col].g = g; // set green of given pixel image[row][col].b = b; // set blue of given pixel } //func2: retun a pixel getPixel(int row, int col) Pixel getPixel(int row, int col) { return image[row][col]; } };

//.cpp file

#include "image.h"

int main() { Image img; Image img2(255, 0, 0); img.changeColor(); Pixel p = img.getPixel(2, 2); cout << p.r;

}

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!