helppppp with my vector c++ project!

I have been doing a project and i'm only at the beginning and i'm already struggling.... so i've made a makefile, vector.cc, testvector.cc, testvector.o, vector.h, vector.o, particle.cc, particle.h, particle.o, testparticle.o, testparticle.cc chamber.cc, chamber.h,

not that it really matters ^^ !! ((test vector is not important here so i will leave it out)
1) vector.h i defined a class vector3D :

class Vector3D
{
public:
Vector3D() : x(0.0), y(0.0), z(0.0){}
Vector3D (double X , double Y, double Z) : x(X) , y(Y) , z (Z) { }

void display() const;
Vector3D operator+ (Vector3D const& V ) const ;
Vector3D operator- (Vector3D const& V ) const ;
Vector3D operator- () const;
double X () const;
double Y () const;
double Z () const ;


private:
double x, y, z;
};


std::ostream& operator<< (std::ostream& a, Vector3D const& V);


2) vector.cc here i defined my functions and stuff


void Vector3D::display() const
{
cout <<"(" << x << "," << y << "," << z << ")" << endl;
}

Vector3D Vector3D::operator+ (Vector3D const& V ) const {
double V1 ( x + V.X () ) ;
double V2 ( y + V.Y() );
double V3 ( z + V.Z() );
Vector3D result ( V1 , V2 , V3 ) ;

return result ;
}

//the above is my addition operator to add two vector classes together. i still haven't written subtraction scalar product and stuff. that doesn't matter for now.


ostream& operator<< (ostream& a, Vector3D const& V) {
a << "(" << V.X() << "," << V.Y() << "," << V.Z() << ")" ;
return a;
} // display operator



double Vector3D::X () const{
return x ; }

double Vector3D:: Y () const{
return y ; }

double Vector3D:: Z () const {
return z ; }

3) this is where i get confused. they say: make a class Particle to represent the molecules of gas. it should possess these attributes :
position
speed in the x y and z coord.
mass
add necessary constructors and adequate methods (destructor if necessary).
Add an overloading external operator << to display the basis info on the particles. make this display in the format :
"pos" : position ; "v" : velocity ; "m" : mass
it's output in terminal would look like :
pos : 1 1 1 ; v : 0 0 0 ; m : 4.002602

make a program testparticle.cc to create 4 particles in which the 4th is a copy of the 2nd. and display the characteristics in this format:
particle 1 : pos : 1 1 1 ; v : 0 0 0 ; m : 4.002602
particle 2 : pos : 1 18.5 1 ; v : 0 0.2 0 ; m : 20.1797
particle 3 : pos : 1 1 3.1 ; v : 0 0 -0.5 ; m : 39.948
particle 4 : pos : 1 18.5 1 ; v : 0 0.2 0 ; m : 20.1797

For me i made a particle.h file where i defined the class particle. my friend suggested the type for the position and velocity should be the type of the previous class we made Vector3D. i thought it would've been better as a double but what do i know. i would like your advice. i coded it like this.

class Particle {

protected:

Vector3D x0, y0, z0; // would it be better as double x0, y0, z0?
Vector3D vx, vy, vz;
long double mass;

public:
Particule(Vector3D X0, Vector3D Y0, Vector3D Z0, Vector3D VX, Vector3D VY, Vector3D VZ, long double m)
: x0(X0), y0(Y0), z0(Z0), vx(VX), vy(VY), vz(VZ), mass(m){}
~Particle();
void display() const;

};

std::ostream& operator<< (std::ostream& par, Particle const& P);

I am not convinced with using type Vector3D. to me it doesn't make sense i would've thought to use double...

and in particle.cc i defined the functions and operator etc..

void Particle::display() const
{
cout << "pos: " << x0 << " " << y0 << " " << z0 << endl;
cout << "v : " << vx << " " << vy << " " << vz << endl;
cout << "m : " << mass << endl;
}


ostream& operator<< (ostream& par, Particle const& P) {
par << "pos : " << P.X0() << P.Y0() << P.Z0()
<< "v : " << P.VX() << P.VY() << P.VZ()
<< "m : " << P.m()
return par;
}

double Particle::X0 () const{
return x0 ; }

double Particle:: Y0 () const{
return y0 ; }

double Particle:: Z0 () const {
return z0 ; }


double Particle::VX () const{
return vx ; }

double Particle:: VY () const{
return vy ; }

double Particle:: VZ () const {
return vz ; }

double Particle:: m () const {
return mass ; } //this whole double particle thing is wrong. i only did it because thats how i displayed the vectors in the vector.cc but i can't write double Particle:: VY as in my class particle the coordinates are not type double but type vector3d. so am i supposed to just write Vector3D Particle:: VY?? or should i just modify the class particle and change them all to double??

I know this is a lot, but most of it is what i wrote however i do feel number 3 with the class particle is totally wrong! please help!! many thanks
closed account (j3Rz8vqX)
Multiple post:
http://www.cplusplus.com/forum/general/133530/
Last edited on
Topic archived. No new replies allowed.