#include <iostream>
using namespace std;
class Color {
private:
int red;
int green;
int blue;
public:
Color(int r, int g, int b)//构造函数
{ setRed(r);
setGreen(g);
setBlue(b) ;
}
int getRed() {
return red;
}
int getGreen() {
return green;
}
int getBlue() {
return blue;
}
void setRed(int r) {
if (r >= 0 && r <= 255) {
red = r;
} else {
red = 0; // 默认值为0
}
}//供主函数输入值的函数
void setGreen(int g) {
if (g >= 0 && g <= 255) {
green = g;
} else {
green = 0;
}
}
void setBlue(int b) {
if (b >= 0 && b <= 255) {
blue = b;
} else {
blue = 0;
}
}
void displayColor() {
cout << "(" << red << ", " << green << ", " << blue << ")" << endl;
}
};//输出函数
int main() {
Color color(10, 12, 200);//构造函数传输值
color.displayColor();
color.setRed(40);
color.setGreen(75);
color.setBlue(55);
cout << "R: " << color.getRed() << endl;
cout << "G: " << color.getGreen() <<endl;
cout << "B: " << color.getBlue() << endl;
return 0;
}