云题海 - 专业文章范例文档资料分享平台

当前位置:首页 > C primer plus(第6版)中文版编程练习答案第15章

C primer plus(第6版)中文版编程练习答案第15章

  • 62 次阅读
  • 3 次下载
  • 2025/5/22 19:20:12

1、 //tv.h

#ifndef TV_H_ #define TV_H_

#include using namespace std;

class Tv { friend class Remote; public: enum { Off, On }; enum { MinVal, MaxVal = 20 }; enum { Antenna, Cable }; enum { TV, DVD }; enum { USUAL, EXCHANGE }; Tv(int s = Off, int mc = 125) :state(s), volume(5), maxchannel(mc), channel(2), mode(Cable), input(TV){} ~Tv(){} void onoff(){ state = (state == On) ? Off : On; } bool ison()const{ return state == On; } bool volup(); bool voldown(); void chanup(); void chandown(); void set_mode(){ mode = (mode == Antenna) ? Cable : Antenna; } void set_input(){ input = (input == TV) ? DVD : TV; } void settings()const; void set_rmode(Remote &r); private: int state; int volume; int maxchannel; int channel; int mode; int input; };

class Remote {

private:

friend class Tv; enum { USUAL, EXCHANGE }; int mode; int fmode; public: Remote(int m = Tv::TV, int f = USUAL) :mode(m), fmode(f){} bool volup(Tv &t){ return t.volup(); } bool voldown(Tv &t){ return t.voldown(); } void onoff(Tv &t){ t.onoff(); } void chanup(Tv &t){ t.chanup(); } void chandown(Tv &t){ t.chandown(); } void set_chan(Tv &t, int c){ t.channel = c; } void set_mode(Tv &t){ t.set_mode(); } void set_input(Tv &t){ t.set_input(); } void mode_show()const{ cout << \};

inline void Tv::set_rmode(Remote &r) { if (ison()) { r.fmode = Remote::EXCHANGE; r.mode_show(); } }

#endif //tvfm.h

#ifndef TVFM_H_ #define TVFM_H_ #include using namespace std;

class Tv;

class Remote {

public: enum State{ Off, On }; enum { MinVal, MaxVal = 20 }; enum { Antenna, Cable }; enum { TV, DVD }; private: int mode;

public: Remote(int m = TV) :mode(m){} bool volup(Tv &t); bool voldown(Tv &t); void onoff(Tv &t); void chanup(Tv &t); void chandown(Tv &t); void set_chan(Tv &t, int c); void set_mode(Tv &t); void set_input(Tv &t); };

class Tv {

public: friend void Remote::set_chan(Tv &t, int c); enum State{ Off, On }; enum { MinVal, MaxVal = 20 }; enum { Antenna, Cable }; enum { TV, DVD }; Tv(int s = Off, int mc = 125) :state(s), volume(5), maxchannel(mc), channel(2), mode(Cable), input(TV){} ~Tv(){} void onoff(){ state = (state == On) ? Off : On; } bool ison()const{ return state == On; } bool volup(); bool voldown(); void chanup(); void chandown(); void set_mode(){ mode = (mode == Antenna) ? Cable : Antenna; } void set_input(){ input = (input == TV) ? DVD : TV; } void settings()const;

private: int state; int volume; int maxchannel; int channel; int mode; int input; };

inline bool Remote::volup(Tv &t){ return t.volup(); }

inline bool Remote::voldown(Tv &t){ return t.voldown(); } inline void Remote::onoff(Tv &t){ t.onoff(); } inline void Remote::chanup(Tv &t){ t.chanup(); }

inline void Remote::chandown(Tv &t){ t.chandown(); } inline void Remote::set_chan(Tv &t, int c){ t.channel = c; } inline void Remote::set_mode(Tv &t){ t.set_mode(); } inline void Remote::set_input(Tv &t){ t.set_input(); }

#endif //tv.cpp

#include \//#include \bool Tv::volup() { if (volume < MaxVal) { volume++; return true; } else return false; }

bool Tv::voldown() { if (volume>MinVal) { volume--; return true; } else return false; }

void Tv::chanup() { if (channel < maxchannel) channel++; else channel = 1; }

void Tv::chandown() { if (channel>1) channel--; else

  • 收藏
  • 违规举报
  • 版权认领
下载文档10.00 元 加入VIP免费下载
推荐下载
本文作者:...

共分享92篇相关文档

文档简介:

1、 //tv.h #ifndef TV_H_ #define TV_H_ #include using namespace std; class Tv { friend class Remote; public: enum { Off, On }; enum { MinVal, MaxVal = 20 }; enum { Antenna, Cable }; enum { TV, DVD }; enum { USUAL, EXCHANGE }; Tv(int s = Off, int mc = 125) :state(s), volume(5), maxchannel(mc), channel(2), mode(Cable), input(TV){} ~Tv(){} void onoff(

× 游客快捷下载通道(下载后可以自由复制和排版)
单篇付费下载
限时特价:10 元/份 原价:20元
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:fanwen365 QQ:370150219
Copyright © 云题海 All Rights Reserved. 苏ICP备16052595号-3 网站地图 客服QQ:370150219 邮箱:370150219@qq.com