Making a class 3D vector on C++.

I want to define a class Vector, representing a 3D vector with the following methods:

display - to display with <<cout>> an object Vector;
e.g. 1.0 3.0 5.0

compare - to test the equality of the current object Vector, with another similar object (i.e. of type Vector) passed in parameter.

Then complete the class Vector, in order to:

1)add 2 vectors
Vector addition(Vector other) const;
which would be used like this:
Vector a, b, c;
(affecting a and b)
c = a.addition(b);

2)substraction
3)the opposite of a vector:
4)Scalar multiplication:
Vector mult(double) const;
used like this -
Vector a, b;
double x;

(affectation of a and x)
b = a.mult(x);

5)Scalar product
6)Cross product

I am completely lost. It is the first stage of the exercise, so we aren't expected to use operators or even constructors in this case(though i know a little bit about them). So its supposed to be simple? but i just can't seem to even get the hang of the first exercise?!
I did

class Vector3D{

public:
void display(double x, double y, double z);
void compare();

private:
double x, y, z;

};

int main(){

Vector3D vect1, vect2;
cout << display() << endl;
return 0;
}

I am soooo lost can someone please help! D:
thanks!!
Also, my friend suggested i use a structure called point, and put it in the class. e.g. struct point{
double x, y, z;
};
then in class Vector3D
Point coord;
Someone else told me that would make it worse and that arrays would be better, while another told me that arrays nor structures are necessary. which is better?
Last edited on
First of all, do you understand what a vector is? To put it simply, it is just a concept with direction and magnitude. As for implementation, it normally doesn't matter, though I would normally expect the subscript operator to be overloaded for something like the vector (operator[]), so an array would be good for that, though a Point structure could work just as well.

You will need a function to set a vector to a value, and probably a constructor as well (it just has to be basic, i.e. take 3 parameters (optionally) and set the x,y,z of the vector to those coordinates.

As for performing operations, look up vectors online to find out how to do them. They aren't all that hard, though.
Topic archived. No new replies allowed.