Escolar Documentos
Profissional Documentos
Cultura Documentos
Enrollment #: _________________________________
Class: _________________________________
Objective
This lab session is dedicated to operator overloading in C++. You will learn the syntax of
overloading arithmetic and relational operators and implement them.
Go through Lab 6 of the manual, attempt the given programs and verify their outputs. Once you
are done, perform the following tasks.
Tasks :
4. What is the syntax of overloading ‘*’ operator for a class Matrix. (You do not need to
write the body of the function)
5. Go through example 6.2 of the manual and write the output of the given code segment.
Exercise 1
Exercise 2
Write a class Complex to model complex numbers and overload the following
operato rs (using member functions).
a. ‘+’ and ‘–‘ o perators for addition and subtraction respectively.
b. ‘~’ operator to find th e conjugate of a complex number.
c. ‘*’ operator to multiply two complex numbers.
d. ‘!’ operato r to find th e magnitud e (absolute value) of a complex number.
Exercise 3
Using non-member functio ns, ov erload the following operators for the c lass
Complex.
a. The ‘>’ operator such that the statement c1>c2 should return true if th e real
part o f c1 is greater than that of c2.
b. The’==’ operator wh ich returns true if the two complex numbers are equal.
Implement the given exercises and get them evaluated by your instructor.
2. Exercise 2
3. Exercuse 3
+++++++++++++++++++++++++