#include //for cerr #include //for the io manipulator setw #include //for exit and EXIT_FAILURE #include "color.h" using namespace std; color::color(int initial_red, int initial_green, int initial_blue) : red(initial_red), green(initial_green), blue(initial_blue) { if (red < 0 || red > 255) { cerr << "bad initial red " << red << "\n"; exit(EXIT_FAILURE); } if (green < 0 || green > 255) { cerr << "bad initial green " << green << "\n"; exit(EXIT_FAILURE); } if (blue < 0 || blue > 255) { cerr << "bad initial green " << green << "\n"; exit(EXIT_FAILURE); } } bool operator==(const color& color1, const color& color2) { return color1.red == color2.red && color1.green == color2.green && color1.blue == color2.blue; } color& color::operator+=(const color& another) { red += another.red; green += another.green; blue += another.blue; return *this; } color& color::operator-=(const color& another) { red -= another.red; green -= another.green; blue -= another.blue; return *this; } color& color::operator*=(double d) { red *= d; green *= d; blue *= d; return *this; } color& color::operator/=(double d) { red /= d; green /= d; blue /= d; return *this; } void color::print() const { cout << '#' << hex << uppercase << setfill('0') << setw(2) << red //setw evaporates after one use << setw(2) << green << setw(2) << blue << dec; } ostream& operator<<(ostream& ost, const color& c) { return ost << '#' << hex << uppercase << setfill('0') << setw(2) << c.red << setw(2) << c.green << setw(2) << c.blue << dec; }