0% found this document useful (0 votes)
5 views8 pages

Object-Oriented Programming LAB # 5

The document outlines an OOP lab experiment focused on C++ friend classes and functions, detailing objectives, assessment criteria, and specific lab tasks. Students are required to create classes for a TV and Remote, implement friend functions for various operations, and explore data sharing between classes. The conclusion emphasizes the benefits of friend functions in maintaining encapsulation while allowing controlled access to private data.

Uploaded by

Anus Babar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views8 pages

Object-Oriented Programming LAB # 5

The document outlines an OOP lab experiment focused on C++ friend classes and functions, detailing objectives, assessment criteria, and specific lab tasks. Students are required to create classes for a TV and Remote, implement friend functions for various operations, and explore data sharing between classes. The conclusion emphasizes the benefits of friend functions in maintaining encapsulation while allowing controlled access to private data.

Uploaded by

Anus Babar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

BCE-2A OOP LAB

AIR UNIVERSITY

DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING


EXPERIMENT: 05

Lab Title: Friend Classes & Friend Functions

Student Name:

Objectives:

This lab is made to develop student understanding related to C++ friend function & friend classes.

LAB ASSESSMENT:

Excellent Good Average Satisfactory Unsatisfactory


Attributes
(5) (4) (3) (2) (1)
Ability to Conduct
Experiment
Ability to assimilate
the results
Effective use of lab
equipment and follows
the lab safety rules

Total Marks: Obtained Marks:

LAB REPORT ASSESSMENT:

Excellent Good Average Satisfactory Unsatisfactory


Attributes
(5) (4) (3) (2) (1)

Data presentation

Experimental results

Conclusion

Total Marks: Obtained Marks:

Date: Signature:

Submitted To: Engr. Sidrish Ehsan


Date: 25-03-2025

Page | 1
BCE-2A OOP LAB

LABORATORY
EXPERIMENT NO.5

Lab Task 01:


Define a TV class representing a television and a Remote class representing a remote control. You
can represent a television with a set of state members—that is, variables that describe various
aspects of the television. Here are some of the possible states:
● On/off
● Channel setting
● Volume setting
● Cable or antenna tuning mode
● TV input (TV or AV)

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

Page | 2
BCE-2A OOP LAB

Page | 3
BCE-2A OOP LAB

Page | 4
BCE-2A OOP LAB

Lab Task 02:


Write a program to find Maximum out of two numbers using friend function. Here one member is
of one class and the second belongs to another class.

Lab Task 03:


Write a program to swap the values of private data members of classes names class_1 and class_2
using friend keyword.

Page | 5
BCE-2A OOP LAB

Lab Task 04:


Create two classes DM and DB which stores the value in distances. DM stores distance in meters
and centimeters and DB in feet and inches. Write a program that can read values for the class
objects and add one object of DM with another object of DB. Use a friend function to carry out the
addition operation. The object that stores the results may be a DM object or DB object, depending
on the units in which the results are required. The display should be in the format of feet and
inches or meters and centimeters depending on the object on display.

Page | 6
BCE-2A OOP LAB

Page | 7
BCE-2A OOP LAB

CONCLUSION
• Friend functions allow controlled access to private data while maintaining encapsulation.
• They enable efficient data sharing between independent classes.
• They provide flexibility by allowing non-member functions to operate on private members.
• They help in implementing operations like swapping values between different classes.

Page | 8

You might also like