tv.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // tv.h -- Tv and Remote classes
  2. #ifndef TV_H_
  3. #define TV_H_
  4. class Tv
  5. {
  6. public:
  7. friend class Remote; // Remote can access Tv private parts
  8. enum {Off, On};
  9. enum {MinVal,MaxVal = 20};
  10. enum {Antenna, Cable};
  11. enum {TV, DVD};
  12. Tv(int s = Off, int mc = 125) : state(s), volume(5),
  13. maxchannel(mc), channel(2), mode(Cable), input(TV) {}
  14. void onoff() {state = (state == On)? Off : On;}
  15. bool ison() const {return state == On;}
  16. bool volup();
  17. bool voldown();
  18. void chanup();
  19. void chandown();
  20. void set_mode() {mode = (mode == Antenna)? Cable : Antenna;}
  21. void set_input() {input = (input == TV)? DVD : TV;}
  22. void settings() const; // display all settings
  23. private:
  24. int state; // on or off
  25. int volume; // assumed to be digitized
  26. int maxchannel; // maximum number of channels
  27. int channel; // current channel setting
  28. int mode; // broadcast or cable
  29. int input; // TV or DVD
  30. };
  31. class Remote
  32. {
  33. private:
  34. int mode; // controls TV or DVD
  35. public:
  36. Remote(int m = Tv::TV) : mode(m) {}
  37. bool volup(Tv & t) { return t.volup();}
  38. bool voldown(Tv & t) { return t.voldown();}
  39. void onoff(Tv & t) { t.onoff(); }
  40. void chanup(Tv & t) {t.chanup();}
  41. void chandown(Tv & t) {t.chandown();}
  42. void set_chan(Tv & t, int c) {t.channel = c;}
  43. void set_mode(Tv & t) {t.set_mode();}
  44. void set_input(Tv & t) {t.set_input();}
  45. };
  46. #endif