Question
Create a C++ class Vector that implements 3-D vectors and has the same specification as the Vector class from the previous exercise, but uses a
Create a C++ class Vector that implements 3-D vectors and has the same specification as the Vector class from the previous exercise, but uses a different representation for the data as described below.
In file Vector.h declare a class Vector with the following properties:
The representation of a Vector should be an array containing three floats giving the magnitudes in the x, y, and z directions. The array should be dynamically allocated on the heap when a Vector is created and deleted when the Vector no longer exists.
There should be a default (0-argument) constructor that initializes a Vector to (0,0,0), a constructor with 3 floats as parameters giving initial values for the x, y, and z magnitudes, and a copy constructor.
There should be a destructor that does whatever work is needed when a Vector object is deleted. If no work is needed, the body of the destructor should be empty.
The class should define assignment on vectors (u=v).
The class should define updating assignment on vectors (u+=v and u-=v) that perform element-by-element addition or subtraction of the vector components.
Operators + and - should be overloaded so that u+v and u-v return new Vectors that are the sum and difference of Vectors u and v, respectively.
Operator * should compute the inner product (dot product) of two Vectors. If v1=(a,b,c) and v2=(d,e,f), then v1*v2 should return the scalar value a*d+b*e+c*f.
Operator * should be overloaded so that if v is the Vector (a,b,c) and k is a double, then v*k and k*v should return new Vectors containing the components of v multiplied by k (i.e., (a*k,b*k,c*k)).
The class should define stream output so that s< The Vector class and associated functions should be placed in a namespace vector333. Note that several of these functions are required to return new Vectors. This means actual Vector values, not pointers to Vectors that have been allocated elsewhere. In file Vector.cc implement this class. In file ex11.cc write a main program that demonstrates that your Vector class works properly. The output format is up to you, but it should be labeled neatly and should be concise so it can be read with pleasure, not pain. Feel free to write using namespace vector333; in your test program so you don't need to type vector333:: repeatedly. Create a suitable Makefile. The command "make" should build an executable program ex11, recompiling individual files only when needed. The command "make clean" should remove the ex11 executable, all .o files, and any editor or other backup files whose names end in ~ . Your code must: compile without errors or warnings on CSE Linux machines (lab workstations, attu, or CSE home VM) have no crashes, memory leaks, or memory errors on CSE linux machines have a Makefile as described above that compiles the code with the g++ options -Wall -g -std=c++11 be pretty: the formatting, modularization, variable and function names, and so on must make us smile rather than cry. (cpplint may help identify things to check, although some of the things it warns about are fine for this exercise.) be robust: you should think about handling bogus input from the user, and you should handle hard-to-handle cases (if there are any) gracefully. have a comment at the top of each source file with your name, student number, and CSE or UW email address. You should submit your exercise using the Gradescope dropbox linked on the main course web page.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started