Question: Given the following class definition: #include usingnamespacestd; classColor { private: intred, green, blue; intcheckAndTruncate(intx); public: Color() { red = 0; green = 0; blue =

Given the following class definition:

#include

usingnamespacestd;

classColor

{

private:

intred, green, blue;

intcheckAndTruncate(intx);

public:

Color() { red = 0; green = 0; blue = 0; }

// Copy constructor

voidsetRed(intr) { red = checkAndTruncate(r); }

voidsetGreen(intg) { green = checkAndTruncate(g); };

voidsetBlue(intb) { blue = checkAndTruncate(b); }

intgetRed() { returnred; }

intgetGreen() { returngreen; }

intgetBlue() { returnblue; }

};

intColor::checkAndTruncate(intx)

{

if(x>= 0 && x<= 255)

returnx;

elseif(x< 0)

{

return0;

}

else

{

return255;

}

}

Add all necessary operators, functions and/or constructors so the that the following main will generate the following output:

Notes:

>> and << operators must be implemented as friend functions.

All other operators should be implemented as member functions.

Notes:

You are not allowed to change anything in the main

You have to implement the copy constructor

intmain()

{

Colorcol1;

Colorcol2;

Colorcol3;

cout <<"Please enter the first color (red green blue):";

cin >>col1;

cout <<"Please enter the second color (red green blue):";

cin >>col2;

cout <<"Please enter the third color (red green blue):";

cin >>col3;

Colorcol4 = col1 +col2;

cout <

return0;

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!