Question: Task 2: Extend the class. ---- PREVIOUS CODE BELOW - Modify the class declaration and definition to overload the +, -, *, / and ==

Task 2: Extend the class. ---- PREVIOUS CODE BELOW

- Modify the class declaration and definition to overload the +, -, *, / and == operators to correctly perform those calculations.

- The + and - operators should accept an input parameter of the same class type and return void. This operation should update the contents of that instance.

- The * and / operators should accept an input parameter of the same type as the private variables holding the x and y values. This will be a scaler multiplication/division, not a vector multiplication/division.

- The == operator should accept an input parameter of the same class type and return a bool indicating if the value is equivalent.

- Modify the class declaration and definition to include a member function returning the magnitude and another returning the angle of the vector.

- You will likely have to change the class declaration beyond the new functions being defined in this task

THEN

Create a program that tests the class.

- Prompt the user for x and y values for the vector.

- Prompt the user for the operation to perform.

- Prompt the user for the values for other vector or scaler to be used in the calculation.

- Display the results (x, y, magnitude and angle of the resultant vector).

- Ask the user if they wish to continue. If so, loop to step b.

- Use your test program to test all member functions and ensure the class is working correctly.

- Test of all operator overload functions.

MyVector.h --------- #ifndef MyVector_h #define MyVector_h #include #include using namespace std; class MyVector{ private: int x, y; public: MyVector(); MyVector(int x1, int y1); MyVector(double magnitude, double angleDegrees); int getX(); int getY(); void setX(int x1); void setY(int y1); void print(); }; #endif

MyVector.cpp -------- #include "MyVector.h" #include MyVector::MyVector(){ x = 0; y = 0; } MyVector::MyVector(int x1, int y1){ x = x1; y = y1; } MyVector::MyVector(double magnitude, double angleDegrees){ double radians = angleDegrees * M_PI / 180; x = magnitude * cos(radians); y = magnitude * sin(radians); } int MyVector::getX(){ return x; } int MyVector::getY(){ return y; } void MyVector::setX(int x1){ x = x1; } void MyVector::setY(int y1){ y = y1; } void MyVector::print(){ cout << "x = " << x << ", y = " << y << endl; }

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!