Question: This lab is an ODA. Please submit whatever you have and don t wait to solve all questions to submit your work. However, it is

This lab is an ODA. Please submit whatever you have and dont wait to solve all questions to submit your work. However, it
is recommended to finish it in your own time.
1. Write a program which has the following properties with non-member overloaded operators detailed below:
(a) Define a class called Vector which has (integer) x and y private members. (Please note that this Vector class has
nothing to do with the vector class in C++.)
(b) Define your getter and setter functions. (Please make the getter functions const once you make sure that things
are working).
(c) Define a default constructor which initializes x and y with 0 by using initialization list.
(d) Define a constructor which initializes both x and y with user defined values initialization list.
(e) Define a display () function which displays x and y components of your vector objects in parentheses like (1,2).
(f) Define the following overloaded operators which are non-member functions:
i. Define an overloaded operator for Vector operator +(const Vector &v1, const Vector &v2) which
can perform vector summation and return a Vector object. (Let v1=(x1, y1) and v2=(x2, y2), then
v1+ v2=(x1+ x2, y1+ y2))
ii. Define an overloaded operator for Vector operator -(const Vector &v1, const Vector &v2) which
can perform vector difference and return a Vector object. (Let v1=(x1, y1) and v2=(x2, y2), then
v1 v2=(x1 x2, y1 y2))
iii. Define an overloaded operator for Vector operator -(const Vector &v1) which returns a Vector ob-
ject which will be in the opposite direction of v1.
iv. Define an overloaded operator for bool operator ==(const Vector &v1, const Vector &v2) which
checks if two vectors are the same and returns either true or false. Youre going to check whether the corre-
sponding components are the same.
2. Make a copy of your solution above and change all non-member overloaded operators to member functions. Please
notice that function headers need to change.
1

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!