반응형
#include <iostream>
using namespace std;
//캡슐화와 데이터 은닉
//데이터 은닉이 왜 필요할까?
// 객체의 불안정성 방지
class Stu
{
private:
int iq; // iq ( 100 ~ 150 )
public:
void Init(int value) { iq = value; }
void Study(int tcnt) {
iq += tcnt;
Print();
}
void Game(int tcnt) {
iq -= tcnt;
Print();
}
private:
void Print() { cout << "IQ : " << iq << endl; }
};
int main()
{
Stu s1;
s1.Init(100);
s1.Study(4);
s1.Game(10);
// s1.iq = 1000;
s1.Game(10);
}
반응형
'01.Bit 단기 > C++' 카테고리의 다른 글
15_생성자오버로딩 (0) | 2018.04.30 |
---|---|
14_생성자 (0) | 2018.04.30 |
12_클래스 (0) | 2018.04.29 |
11_C++구조체 (0) | 2018.04.29 |
10_날짜활용실습(3단계) (0) | 2018.04.29 |
댓글