(Please give all the solutions and steps, if you give the answer by picture plea
ID: 3914683 • Letter: #
Question
(Please give all the solutions and steps, if you give the answer by picture please post a clear picture. Please don't answer the question if you can't do all the questions, THANKS).
1. (50 points) Write the definitions for the functions of the class below that stores infor mation about a 2-D vector. The class should have functions to set and get the x and y integer components. Overload theoperator to return the dot product of two vectors as (A x B) +(Ay x By). Overload the operator to also return an integer multiple of the given vector. Overload theoperator to check whether two vectors have equal magnitudes, where the magnitude is given as yA + A function. The class also needs to track how many vector instances are available at any given time using the static variable. using the calculateMagnitude class Vector2D public Vector2DO; //Default constructor Vector2D(int newX, int newY); //Additional constructor Vector2D(int ne«XValue); //Horizontal vector constructor, y-coordinate is zero friend bool operator (const Vector2D&k; vector1, const Vector2D&vector2;); friend const int operator * (const Vector2D& vectorl, const Vector2D& vector2); friend const Vector2D& operator * (int n, const Vector2D& vector1); void setX(int new%); void setY(int newY); int getXO; int getYO; double calculateMagnitude ); private int x; int y; static int numberOfVectors; b: int Vector2D: :numberOfVectors 0; (a) (5 points) Vector2D: : Vector2DC) I //Set x and y to 0, and increment the number of vectorsExplanation / Answer
#include<iostream>
#include<math.h>
using namespace std;
class vector2D{
int x;
int y;
static int no_of_vectors;
public:
vector2D();
vector2D(int newx,int newy);
vector2D(int newx);
void setx(int newx);
void sety(int newy);
int getx();
int gety();
double calculateMagnitude();
friend bool operator==(const vector2D&vector1,const vector2D&vector2);
friend const int operator*(const vector2D&vector1,const vector2D&vector2);
friend const vector2D& operator*(int n,const vector2D&vector1);
};
int vector2D::no_of_vectors=0;
vector2D::vector2D(){
x=0;y=0;
}
vector2D::vector2D(int newx,int newy){
x=newx;
y=newy;
no_of_vectors++;
}
vector2D::vector2D(int newx){
x=newx;
y=0;
no_of_vectors++;
}
void vector2D:: setx(int newx){
x=newx;
}
void vector2D:: sety(int newy){
y=newy;
}
int vector2D:: getx(){
return x;
}
int vector2D::gety(){
return y;
}
double vector2D:: calculateMagnitude(){
int sum=x*x+y*y;
double result=sqrt(sum);
return result;
}
bool operator==(const vector2D&vector1,const vector2D&vector2){
if(vector1.x==vector2.x&&vector1.y==vector2.y)return true;
else return false;
}
const int operator*(const vector2D&vector1,const vector2D&vector2){
return (vector1.x*vector2.x+vector1.y*vector2.y);
}
const vector2D& operator*(int n,const vector2D&vector1){
vector2D v;
v.x=vector1.x*n;
v.y=vector1.y*n;
return v;
}
int main(){
return 0;
}
for any query please comment.
please upvote if find it helpful.
Thank you!
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.