1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | #include <iostream> #include <string> using namespace std; class Circle { int radius; public: Circle(int radius = 0) { this->radius = radius; } int getRadius() { return radius;} void setRadius(int radius) { this->radius = radius; } double getArea() { return 3.14*radius*radius; } }; class NamedCircle :public Circle { string name; public: NamedCircle(int radius, string name) :Circle(radius) { this->name = name; } void show() { cout << "반지름이 " << getRadius() << "인 " << name << '\n'; } }; int main() { NamedCircle waffle(3, "waffle"); waffle.show(); } | cs |
'Programming > 명품 C++ Programming' 카테고리의 다른 글
| 명품 C++ Programming 실습문제 8장 3번 (0) | 2018.06.19 |
|---|---|
| 명품 C++ Programming 실습문제 8장 2번 (0) | 2018.06.19 |
| 명품 C++ Programming 8장 OpenChallenge (0) | 2018.06.19 |
| 명품 C++ Programming 실습문제 7장 10번 (0) | 2018.06.18 |
| 명품 C++ Programming 실습문제 7장 9번 (0) | 2018.06.18 |