tvfm.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // tvfm.h -- Tv and Remote classes using a friend member
  2. #ifndef TVFM_H_
  3. #define TVFM_H_
  4. class Tv; // forward declaration
  5. class Remote
  6. {
  7. public:
  8. enum State{Off, On};
  9. enum {MinVal,MaxVal = 20};
  10. enum {Antenna, Cable};
  11. enum {TV, DVD};
  12. private:
  13. int mode;
  14. public:
  15. Remote(int m = TV) : mode(m) {}
  16. bool volup(Tv & t); // prototype only
  17. bool voldown(Tv & t);
  18. void onoff(Tv & t);
  19. void chanup(Tv & t);
  20. void chandown(Tv & t);
  21. void set_mode(Tv & t);
  22. void set_input(Tv & t);
  23. void set_chan(Tv & t, int c);
  24. };
  25. class Tv
  26. {
  27. public:
  28. friend void Remote::set_chan(Tv & t, int c);
  29. enum State{Off, On};
  30. enum {MinVal,MaxVal = 20};
  31. enum {Antenna, Cable};
  32. enum {TV, DVD};
  33. Tv(int s = Off, int mc = 125) : state(s), volume(5),
  34. maxchannel(mc), channel(2), mode(Cable), input(TV) {}
  35. void onoff() {state = (state == On)? Off : On;}
  36. bool ison() const {return state == On;}
  37. bool volup();
  38. bool voldown();
  39. void chanup();
  40. void chandown();
  41. void set_mode() {mode = (mode == Antenna)? Cable : Antenna;}
  42. void set_input() {input = (input == TV)? DVD : TV;}
  43. void settings() const;
  44. private:
  45. int state;
  46. int volume;
  47. int maxchannel;
  48. int channel;
  49. int mode;
  50. int input;
  51. };
  52. // Remote methods as inline functions
  53. inline bool Remote::volup(Tv & t) { return t.volup();}
  54. inline bool Remote::voldown(Tv & t) { return t.voldown();}
  55. inline void Remote::onoff(Tv & t) { t.onoff(); }
  56. inline void Remote::chanup(Tv & t) {t.chanup();}
  57. inline void Remote::chandown(Tv & t) {t.chandown();}
  58. inline void Remote::set_mode(Tv & t) {t.set_mode();}
  59. inline void Remote::set_input(Tv & t) {t.set_input();}
  60. inline void Remote::set_chan(Tv & t, int c) {t.channel = c;}
  61. #endif