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.
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;
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