#include <iostream> using namespace std;
class Circle1 //내측 원 { private : int xpos; int ypos; int radius1;
public : void Init(int x, int y, int r) //정보 은닉 { xpos = x; ypos = y; radius1 = r; }
void ShowInInfo() const { cout << "반지름: " << radius1 << endl << '[' << xpos << ',' << ypos << ']' <<endl; } };
class Circle2 //외측 원 { private : int xpos; int ypos; int radius2;
public : void Init(int x, int y, int r) { xpos = x; ypos = y; radius2 = r; }
void ShowOutInfo() const { cout << "반지름: " << radius2 << endl << '[' << xpos << ',' << ypos << ']' <<endl; } };
class Ring { private : Circle1 Inner; Circle2 Outter; public : void Init(int x1, int y1, int z1, int x2, int y2, int z2) { Inner.Init(x1,y1,z1); //private 멤버 변수에 직접 접근은 불가능하지만 이렇게는 가능하다. Outter.Init(x2,y2,z2); } void ShowRingInfo() const //나름대로 캡슐화 { cout << "내측 원의 정보..." << endl; Inner.ShowInInfo(); cout << "외측 원의 정보..." << endl;; Outter.ShowOutInfo(); } };
int main(void) { Ring ring; ring.Init(1,1,5,2,2,8); ring.ShowRingInfo(); return 0; } |