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 | #include <iostream> #include <string> using namespace std; class Point { int x, y; public: Point(int x, int y) { this->x = x; this->y = y; } int getX() { return x; } int getY() { return y; } protected: void move(int x, int y) { this->x = x; this->y = y; } }; class ColorPoint :public Point { string color; public: ColorPoint(int x = 0, int y = 0, string color = "BLACK") :Point(x, y) { this->color = color; } void setPoint(int x, int y) { move(x, y); } void setColor(string color) { this->color = color; } void show() { cout << color << "색으로 (" << getX() << ", " << getY() << ")에 위치한 점입니다.\n"; } }; int main() { ColorPoint zeroPoint; zeroPoint.show(); ColorPoint cp(5, 5); cp.setPoint(10, 20); cp.setColor("BLUE"); cp.show(); } | cs |
'Programming > 명품 C++ Programming' 카테고리의 다른 글
명품 C++ Programming 실습문제 8장 6번 (0) | 2018.06.19 |
---|---|
명품 C++ Programming 실습문제 8장 5번 (0) | 2018.06.19 |
명품 C++ Programming 실습문제 8장 3번 (0) | 2018.06.19 |
명품 C++ Programming 실습문제 8장 2번 (0) | 2018.06.19 |
명품 C++ Programming 실습문제 8장 1번 (0) | 2018.06.19 |