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:
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;
};
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.