명품 C++ programming 실습 문제 4장 1번

문제 : 다음은 색의 3요소인 red, green, blue로 색을 추상화한 Color 클래스를 선언하고 활용하는 코드이다. 빈칸을 채워라. red, green, blue는 0~255의 값만 가진다. 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 #include using namespace std; class Color { int red, green, blue; public: Color() {red = green = blue = 0;} Color(int r, int g, int b) {red = r; green = g; blue = b;} void setColor(int r, int g, int b) {red = r; green = g; blue = b;} void show() {cout « red « ’ ’ « green « ’ ’ « blue « endl;} }; int main() { Color screenColor(255,0,0); // 빨간색의 screenColor 객체 생성 Color *p; // Color 타입의 포인터 변수 p 선언 _____ // (1) p가 screenColor의 주소를 가지도록 코드 작성 _____ // (2) p와 show()를 이용하여 screenColor 색 출력 _____ // (3) Color의 일차원 배열 colors 선언. 원소는 3개 _____ // (4) p가 colors 배열을 가리키도록 코드 작성 // (5) p와 setColor()를 이용하여 colors[0], colors[1], colors[2]가 // 각각 빨강, 초록, 파랑색을 가지도록 코드 작성 _____ _____ _____ // (6) p와 show()를 이용하여 colors 배열의 모든 객체의 색 출력. for 문 이용 _____ _____ _____ } 목적 및 힌트 : ...

March 4, 2020 · 3 min · Sobamemil