Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ PROGRAMMING (this isnt a project its just a quick program, much easier than

ID: 3800365 • Letter: C

Question

C++ PROGRAMMING (this isnt a project its just a quick program, much easier than it looks) it is due soon so please help me so i can give 5 stars <3

Code Needed:

In this project you will implement operator overloading for a two dimensional Vector class. Begin with the declaration of the Vector class on the final page. There are three operators that must be overloaded insertion addition and subtraction insertion The insertion operator is used to send the values of a vector to an ostream object, if a vector has two values 2.0 and 3.1 it must insert into the string "(2.0, 3.1)". For example, code Segment A will produce the Output A Segment A Vector v (2.2, 3.1) cout "Vector v1: v endli output A Vector v1 (2.2, 3.1) addition The addition operator is used to sum two vectors together. Addition is pairwise, x is added to x, and y to y. The result of the operation is a new object that contains the sum of the two Vectors as a si e vector. Code given in Segment B produces the Output B Segment B Vector v1 (2.0 3.1) v2 (4.3 v2 v1 v2 endl. cout v1 output B v1 v2 (6.3, 8.1)

Explanation / Answer

Modify Vector.h as follows:

#include <iostream>

using namespace std;

class Vector {
public:
/* Default constructor, sets x and y to zero */
Vector(){
       x = y = 0;
   }

/* Parameterized constructor, sets x to Xval, and y to yVal */
Vector(float xVal, float yVal){
       x = xVal;
       y = yVal;
   }

/* Returns the floating point values of the x and y */
float getX() const{   return x;   }
float getY() const{    return y;   }

/*
* Inserts into the stream the string "(, )" where
* is the floating point value for x
* is the floating point value for y
*/
friend ostream& operator<<(ostream& os, const Vector &v){
       return os << '(' << v.x << ',' << v.y << ')';
   }


/*
* Sums two Vectors v1 and v2 together returning a new vector v3
* Where addition is defined as
* v3.x = v1.x + v2.x
* v3.y = v1.y + v2.y
*/
Vector operator+(const Vector &other) const{
   Vector v3;

   v3.x = this->x + other.x;
   v3.y = this->y + other.y;

   return v3;

   }

/*
* Subtracts v2 from v1 returning a new vector v3
* Where addition is defined as
* v3.x = v1.x - v2.x
* v3.y = v1.y - v2.y
*/
Vector operator-(const Vector &other) const{
   Vector v3;

   v3.x = this->x - other.x;
   v3.y = this->y - other.y;

   return v3;

   }

private:
float x, y;
};

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote