BCE-2A OOP LAB
AIR UNIVERSITY
DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING
EXPERIMENT: 06
Lab Title: Operator Overloading in C++
Student Name:
Objectives:
This lab is made to develop student understanding related to C++ Operator Overloading.
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: 8-04-2025
Page | 1
BCE-2A OOP LAB
LABORATORY
EXPERIMENT NO.6
Lab Task 01:
Overload the * operator to multiply two matrices. Create a class Matrix with:
• A 2D array as a private data member.
• A constructor to initialize matrix elements.
• An overloaded * operator for matrix multiplication.
• A function to display the matrix.
• Implement matrix multiplication using the overloaded operator.
Page | 2
BCE-2A OOP LAB
Lab Task 02:
Implement a class Number that overloads the % operator to find the remainder when dividing two
numbers. Create a class Number with:
• Private data member value.
• A constructor to initialize the value.
• An overloaded % operator to perform modulus operation.
• A function to display the result.
Page | 3
BCE-2A OOP LAB
Lab Task 03:
Overload the “==” and “!” operator to compare two string objects. Create a class MyString with:
• A private character array or string data type.
• A constructor to initialize the string.
• An overloaded == operator to compare two strings and ! operator incase not equal.
• A function to display the string.
Page | 4
BCE-2A OOP LAB
CONCLUSION
• Operator overloading enhances the functionality of existing operators by allowing them to
work with user-defined data types, leading to more intuitive and readable code.
• It enables objects of custom classes to be manipulated using standard operators, simplifying
operations like addition, subtraction, and comparison.
• Proper implementation of operator overloading ensures that operators behave consistently and
logically, preventing potential confusion or errors in the code.
• While powerful, operator overloading should be used cautiously to avoid excessive complexity
and ensure that the code remains maintainable and understandable.
Page | 5