Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please correct and rewrite the following C++ code with correct functions and constructors //image.h #pragma once #include using namespace std; struct Pixel { int r;

Please correct and rewrite the following C++ code with correct functions and constructors

//image.h

#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]; } };

//image.cpp

#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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions