电视机类

“【问题描述】

    补全设计一个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”<

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值