0% found this document useful (0 votes)
52 views

Lab Report 12

This document summarizes M Saim Ashraf's lab report on operator overloading in C++. It includes 6 examples and 5 tasks demonstrating overloading operators like increment, addition, subtraction, division, extraction and insertion for classes like Time, Box, Date, Counter, Complex, and Distance. The examples overload operators like ++, +, - to perform actions like incrementing time, adding boxes, and extracting/inserting dates. The tasks involve overloading operators for counters, complex numbers, and distances to perform operations like incrementing, addition, and conversion between feet and inches.

Uploaded by

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

Lab Report 12

This document summarizes M Saim Ashraf's lab report on operator overloading in C++. It includes 6 examples and 5 tasks demonstrating overloading operators like increment, addition, subtraction, division, extraction and insertion for classes like Time, Box, Date, Counter, Complex, and Distance. The examples overload operators like ++, +, - to perform actions like incrementing time, adding boxes, and extracting/inserting dates. The tasks involve overloading operators for counters, complex numbers, and distances to perform operations like incrementing, addition, and conversion between feet and inches.

Uploaded by

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

Object Oriented Programming

Lab Report #12

Name M Saim Ashraf

Registration FA21-BEE-128
Number

Class BEE-3A

Instructor’s Dr. Riaz Hussain


Name
Lab 12 – Operator Overloading
Example 1
In this example, we use increment (++) operator. We overloaded this operator for prefix and for
postfix. We make a class of Time whose data members are hours and minutes. We use this
operator to increment time.
Link: https://onlinegdb.com/1Xf1Hd8Bl

Example 2
This example is about binary operators. Binary operators contain two operands. It includes
addition (+), subtraction (-) and other operators. In this example, we overloaded the addition
operator. We make a class of box having length, breath and height as its data members.
Link: https://onlinegdb.com/mzthU0bxR

Example 3
This example is about stream operators. Stream operators contains insertion and extraction
operators. In this example, we make a class of Date. We use the insertion operator. We declared
the overloaded << operator function as a friend of class Date to get an access of the private data
within a Date object.
Link: https://onlinegdb.com/PrdUd2AMY

Task 5.1
In this task, we make a base class of counter. We use the increment (++) operator. We
overloaded the increment operator for the counter class. We make the object of the counter class
and uses it as a loop counter for printing a table in main function.
Link: https://onlinegdb.com/yx13ARwsb-

Task 5.2
In this task, we use binary operator of addition (+). We make a class of complex. It contains the
real and imaginary part separately. We overload the + operator for this class. The class contains
the get and show data functions who take the values from the user and display them.
Link: https://onlinegdb.com/4tOHWJEHp
Task 5.3
In this task, we create a class of distance. It has feet and inches as data members. We uses %
operator which divides the given numerator by the denominator to find a result. In this program,
through % operator when we divide any number with 12, the value of the quotient will come
under the feet and the value of remainder will come under the inches.
Link: https://onlinegdb.com/VkacMImG9

Task 6.1
In this task, we make a calculator for the complex numbers using all types of operators. We
make a class of complex numbers. We overloaded all the operators that are ++, --, +, -, /, *, >>,
<<. We make functions for each operator and in its definition, we include both its real and
imaginary parts.
Link: https://onlinegdb.com/aNb2Gqy8i

You might also like