小鈺專用

小白_不太白發表於2024-07-03
#include <iostream>

using namespace std;

class Color {
private:
    int red;
    int green;
    int blue;

public:
    // 建構函式
    Color(int r, int g, int b) : red(r), green(g), blue(b) {}

    // 成員函式,輸出顏色資訊
    void printColor() {
        cout << "當前顏色Color(" << red << "," << green << "," << blue << ")" << endl;
    }
};

int main() {
    int r, g, b;
    cout << "請輸入紅、綠、藍三個顏色分量(整數,空格分隔):" << endl;
    cin >> r >> g >> b;

    // 建立Color物件
    Color color(r, g, b);

    // 輸出顏色資訊
    color.printColor();

    return 0;
}

相關文章