You are on page 1of 3

Lab Journal Lab 6

Object Oriented Programming Lab Journal - Lab 6


Name: _________________________________

Enrollment #: _________________________________ Class: Objective This is the second session in the series of labs on operator overloading. This lab will introduce you to overloading of relational operators and overloading operators using non-member functions. Go through Lab 6 of the manual, attempt the given programs and verify their outputs. Once you are done, perform the following tasks. Tasks : Answer the following/Write C++ code where required. 1. Write the declaration of function to overload == operator for a class Distance with members feet and inches. _________________________________

2.

Write the declaration of the function in part 1 above if it is implemented as a nonmember function.

Object Oriented Programming

Page 1

Lab Journal Lab 6

3.

Can we overload the < operator for integers?

4.

Using operator overloading can we change the number of operands of an operator?

5.

Assume that + is overload for class Distance. Can we write the following statement.
Distance d1, d2(3,4), d3(4,5), d4(6,7); d1 = d2 + d3 + d4;

Exercise 1
Create a class Integer to simulate the integer data type in C++. Th e class will have one integer data member. Prov ide constructors and get()/set() methods. Overload the fo llowing relational operators. <, >, ==, !=, +, -

Overload each o f these using class member functions.

Object Oriented Programming

Page 2

Lab Journal Lab 6

Exercise 2
Repea t ex ercise1 by overloading the mentioned operators using nonmember functions.

Do Exercises 1 and 2 and get them checked by your instructor. S No. 1. 2. Exercise Exercise 1 Exercise 2 Checked By:

+++++++++++++++++++++++++

Object Oriented Programming

Page 3

You might also like