Question: please use c++, -------------------------here is the background: The Problem We are going to work on making our own data structures using a C++ struct. Specifically
please use c++, -------------------------here is the background:
The Problem
We are going to work on making our own data structures using a C++ struct. Specifically we are going to create both data members and member functions. We are going to make a 2D MathVector struct. Too keep it straight, these are the mathematical entitles called Vectors (a geometric entity with direction and magnitude).
Some Backgroud
So if you don't remember, here is a little background on two-dimensional vectors. A vector is basically an arrow that has a magnitude (a length) and a direction (an angle with respect to typically the x axis). It usually is represented as an x,y pair, where the origin of the vector is assumed to be at 0,0 and the head of the vector is as the listed x,y pair.

Here are some of the operations you can perform on your new MathVector struct.
MathVector addition. If V1 is (x,y) and V2 is (a,b), the V+W is (x+a,y+b), returning a new MathVector
MathVector multiplication by a scalar integer type. If V1 is (x,y), then V*n is (x*n,y*n), returning a new MathVector
MathVector multiplication with another MathVector. There are two possibilities, dot product or cross product. We'll do dot product. If V=(x,y) and W=(a,b), then V*W = x*a + y*b, a scalar. Thus the dot product returns a scalar type long, not a MathVector
magnitude. The magnitude based on the Pythagorean theorem for a V=(x,y) says that the magnitude is sqrt(x^2 + y^2). Returns a double
---------------------------------------------------Here is the task:
Make a MathVector struct. Data members are:
long x
long y
Constructors are:
1,default constructor
2,two args, each a long, constructor: first arg is the x value, the second is the y value. No defaults.
The member functions are:
1,MathVector add(const MathVector&). Single arg a const ref to MathVector. Adds two MathVectors as described. Returns a new MathVector.
2,MathVector mult(long). Multiplies a single MathVector element by a long as described. Returns a new MathVector.
3,long mult(const MathVector&). Single arg a const ref to MathVector. Multiplies the two MathVectors as a dot product, yielding a long as described above.
4,double magnitude(). No args. Calculate the magnitude of the MathVector as described. Returns a double.
Make the following regular function (not a member):
1,string vec_to_str(const MathVector &v). No args, returns a string representation of the MathVector in the format: "x:y"
Make a "vector.h" and a "vector.cpp" to store your MathVector struct. Compile it with the "main.cpp" that is in the lab directory and run.
and here is the main.cpp:
#include #include using std::cout; using std::endl; using std::string; #include "vector.h" int main (){ long scalar=20; MathVector v1; MathVector v2(3,2); long long_result; double dbl_result; MathVector vec_result; cout 0.0 A vector V-+W V W V+W V-W SW V+V 2 V V 2 Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
