“【问题描述】
补全设计一个TV类和一个Remote类。Remote类的成员函数是TV类的友元, 电视类有状态、频道和音量基本属性,默认初始频道为5,默认初始音量为20。状态有开和关(-1表示关机状态,其他为开机状态)。
在主函数根据输入的op值进行不同操作。补全代码使程序满足如下要求。
【输入形式】
当op==1时,
输入电视操作命令如下:
OFF_ON(切换电视开关机状态)
VOL_UP(电视音量+1)
VOL_DOWN(电视音量-1)
CHA_NEXT(电视频道+1)
CHA_PRE(电视频道-1)
CHA_TO x(0<=x<=100,将电视频道切到x)
VOL_TO x(0<=x<=100,将电视音量切到x)
其中CHA_TO与VOL_TO通过调用友元类实现。
当op==2时,输出当前电视状态。
当op==3时,结束程序。
【输出形式】
当op==2时,输出当前电视状态,具体格式见样例。
【样例输入】 【对应样例输出】
2 The TV is OFF
1 OFF_ON
2 The TV is ON
The channel is 5
The volume is 20
1 VOL_UP
2 The TV is ON
The channel is 5
The volume is 21
1 CHA_TO 30
2 The TV is ON
The channel is 30
The volume is 21
1 VOL_TO 30
2 The TV is ON
The channel is 30
The volume is 30
3
include
using namespace std;
class TV;
class Remote
{
public:
Remote() {};
void volume_to(TV &tv, int x);
void channel_to(TV &tv, int x);
};
class TV
{
private:
int state;
int channel;
int volume;
public:
friend void Remote::volume_to(TV &tv, int x);
friend void Remote::channel_to(TV &tv, int x);
TV() {};
TV(int st) :state(st),channel(5),volume(20){};
void onoff() {
if(state==-1)
state=1;
else
state=-1;
}
void cha_next() {
channel++;
}
void cha_pre() {
channel–;
}
void vol_up() {
volume++;
}
void vol_down() {
volume–;
}
void print() {
if(state == -1) {
cout<<”The TV is OFF”<