Professional Documents
Culture Documents
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.
Page 1
3.
4.
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. <, >, ==, !=, +, -
Page 2
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:
+++++++++++++++++++++++++
Page 3