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 < cout < cout < cout < return0;
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