CS 54 - Lab 12


Lab Assignment

KMNR recently hired a new DJ, Sean Smith, to work from 13:37 to 00:42 every Thursday. Sean is excited about his new job, so he plays with three radios at a time to practice DJing before being put on the air. Being the astute computer science student he is, he first tries to simulate this in C++. He templates this functionality using the following class:

template <class T>
class Radio
{
public:
  Radio();
  Radio(const T &newBand);
  bool isOn() const;
  T getBand() const;
  void print() const;
  void setBand(const T &newBand);
  void operator!(); /* this should invert the status of the power switch */

private:
  T band;
  bool power;
};


Lab Assignment - Part I (Required - 8 Points)

Sean is a Sustaining Contributor of the Free Software Foundation, so he wrote some C++ classes to simulate the different types of bands for the radio and posted them on his web site under the LGPL. Sean's files are here: (header file) (C++ file)

Take Sean's band code and implement a templated Radio. In your main() function, be sure to create three radios (one of each type of band) and print the output from radios. In particular, Sean wanted you to:

Don't forget to turn a radio off and print in your main() function to make sure the print() function works as expected.


Lab Assignment - Part II (Quasi Required - 10 Points)

Sean connected all the radios to a DC power supply and ka-BOOM! The power supply exploded! After putting out the fire, Sean realized that since the AM, FM, and IceCast radios had resistances of 20, 30, and 50 Ω, he shorted the radios out because he overloaded the power supply, which has an effective operating range of 42 V - 90 V. Mathematically, we get that the voltage needed, V, is:
V = 20SA + 30SF + 50SI
, where {SA, SF, SI} represent the status of the power flag (i.e., we get 0 if that radio is off, 1 if that radio is on). Add functionality to your main() function that will predict whether the power supply will explode or not (assume it explodes if the power supply is either overloaded or underloaded).

NOTE: Do NOT hard code the results for this part (i.e., don't figure out the results in advance and write if's based on what is on or off). Instead, do it mathematically based on the voltage of the system.


Lab Assignment - Part III (Extra Credit - 12 Points)

Implement another band that is consistent with Sean's original implementation. Be creative on the architecture of the band. Just make sure that all the operations you did in your main() in Part I work for the new band.


Grading & Submission

Part I is worth 8 points. Part II is worth 10 points (Part I + 2 more points). Part III is worth 12 points (Part II + 2 points extra credit). The lab is out of 10 points. When you're done, submit your lab12.tar.gz file on Blackboard. I will be grading your program on the following criteria:


[Dilbert]