hello everybody,
I'm a student of computer engineering and i need help with a home work received
in data structures
it says:
"write C++ class declaration for a class called VECTOR and a code for handling n dimensional
vector. The dimension n is a variable and will be specified as a parameter to
the constructor. If n is not specified, a default value of 1 is to be used.
The class should have at least the following member functions:
get_length( ) : computes the length of the vector.
read_vector( ) : reads the vector.
print _vector( ) : prints the vector.
constructor(s) and destructor.
Use operator overloading for
adding two vectors : V3 = V1 + V2
subtracting two vectors V3 = V1 - V2
Dot product: V3 = V1 * V2
Your functions should add subtract and multiply vectors only if they have the same
dimension. If not, display an error message.
HINTS:
Include any necessary data members and any other function you may need.
Write a main function to test your class.
A vector of dimension n is given by :
V = (v0, v1, v2, ----, vn-1)".
Now i didn't understand what "n dimensional vector" mean ??
does it mean the number of dimension (like: x,y,z) ?
or number of vectors ?
and if it mean number of dimension, how could i know if any two of these vectors in the same direction or not ?
what is he mean with this "V = (v0, v1, v2, ----, vn-1)" ?
To start, lets consider a point in 3-dimensional space, with a set of x, y, and z coordinates. We can express the coordinates of this point as a 3 dimensional vector (V):
V=xi+yj+zk
or
V=(x,y,z)
What you want to do here is instead of considering only 3 points, consider an arbitrarily number of components. This is what is meant by n-dimensional-n is an arbitrary number that can be assigned any integer value.
As for "V = (v0, v1, v2, ----, vn-1)", remember that C++ initializes arrays from index 0 by default. So a 3-dimensional vector would have indices of 0, 1, and 2.