Professional Documents
Culture Documents
LAB #06: Friend Classes: Description
LAB #06: Friend Classes: Description
LAB #06: Friend Classes: Description
LAB #06:
Friend Classes
Description:
Friendship helps in accessing the private data members of class. Thus it enables a class to grant
the access to any other class without inheriting that class. If two classes do not fulfill “is-a”
relationship and are required to access the private member function of any class it is declared
as friend class of that class. Friend functions are also meant for the same purpose.
Friend classes
All member functions of a class become friends of the friendship-granting class. Friendship-
granting class allows the other class to access all the private, protected, public members
directly using (.) operator with Friendship-granting class object.
LAB TASK
•Channel setting
•Volume setting
The input selection chooses between TV, which could be either cable or broadcast TV,
and a VCR. Some sets may offer more choices, such as multiple VCR/DVD inputs, but this
list is enough for the purposes of this
example. Also, a television has some
parameters that aren’t state variables. For
example, televisions vary in the
number of channels they can receive, and
you can include a member to track that
value. i.e. Max Channels and Max
volume. Viewer can also be able to see the following settings if
TV is on
“Volume setting = “
“Channel setting = “
“Mode = “
“Input = “
Next, you must provide the class with methods for altering the settings. Many
televisions these days hide their controls behind panels, but it’s still possible with most
televisions to change channels, and so on, without a remote control. However, often
you can go up or down one channel at a time but can’t select a channel at random.
Similarly, there’s usually a button for increasing the volume and one for decreasing the
volume.
A remote control should duplicate the controls built in to the television. A single remote
of a company control can control several televisions of the same company. Many of its
methods can be implemented by using TV methods. In addition, a remote control
typically provides random access channel selection. That is, you can go directly from
channel 2 to channel 20 without going through all the intervening channels. Also, many
remotes can work in two modes—as a television controller and as a VCR controller.
TEST PLAN
Commands Output
Television t;
Remote r;
r.setChannel(t,25);
r.VolumeUp();
r.VolumeDown();
r.viewSettings(t);
r.setMode(t);
Television g=t;
r.setChannel(g,1);
r.channelDown();
r.channelDown();
r.viewSettings(g);
II. Overload >> operator using operator overloading and fiend function concept for
Complex class