1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
int main()
{
Color background(0, 270, 84);
Color A( 17, 204, 150);
A.output();
cout << endl;
Color green(0, 255, 0);
Color blue(0, 0, 255);
mixture(green, blue).output();
}
//Constructor functions Definition
Color::Color(unsigned red, unsigned green, unsigned blue)
:redVal(red), greenVal(green), blueVal(blue)
{
if (red<0 && red>255) die("Invalid red coordinate");
if (green<0 && green>255) die("Invalid green coordinate");
if (blue<0 && blue>255) die("Invalid blue coordinate");
}
//Accessor functions Definition
unsigned Color::getRed() const
{
return redVal;
}
unsigned Color::getGreen() const
{
return greenVal;
}
unsigned Color::getBlue() const
{
return blueVal;
}
//Mutator functions Definition
Color & Color::setRed(unsigned red)
{
redVal = red;
return *this;
}
Color & Color::setGreen(unsigned green)
{
greenVal = green;
return *this;
}
Color & Color::setBlue(unsigned blue)
{
blueVal = blue;
return *this;
}
//
const Color & Color::output() const
{
cout <<"<"<< redVal << "," << greenVal << "," << blueVal <<">"<< endl;
return *this;
}
|