main.cpp
#include <iostream>
using namespace std;
// private: protected: public:
struct TV
{
//private:
bool powerOn;
int channel;
int volume;
public:
void on()
{
powerOn = true;
cout << "TV를 켰습니다." << endl;
}
void off()
{
powerOn = false;
cout << "TV를 껐습니다." << endl;
}
void setChannel(int _cnl)
{
if(_cnl >= 1 && _cnl <= 999)
{
channel = _cnl;
cout << "채널을" << _cnl << "으(로) 바귔습니다." << endl;
}
}
void setVolume(int _vol)
{
if (_vol >= 0 && _vol <= 100)
{
volume = _vol;
cout << "볼륨을" << _vol << "으(로) 바귔습니다." << endl;
}
}
TV()
: powerOn()
, channel(0)
, volume(7)
{
}
};
int main()
{
TV lg;
lg.on();
lg.setChannel(10);
lg.setVolume(50);
}
public = 어디서든 접근이 가능.
protected = 상속관계일 때 접근이 가능
private = 해당 클래스에서만 접근이 가능