/*********************************************************************** * M_Vector.h * * Header file for an implementation of mathematical vectors of doubles. * Features overloading of basic arithmetic and comparison operators. * * Written by Paul Bonamy - 30 October 2009 ************************************************************************/ #ifndef M_VECTOR_H #define M_VECTOR_H #include using namespace std; /*********************************************************************** * Relatively simple mathematical vector class ***********************************************************************/ class M_Vector { public: // constructors M_Vector(); // default constructor - vector of size 0 M_Vector(int s); // vector of given size M_Vector(const M_Vector &v); // copy constructor M_Vector(double a[], int s); // vector from array and size // destructor ~M_Vector(); // support functions int getSize(); // returns size of vector // operators overloaded as global functions friend ostream& operator<< ( ostream & out, const M_Vector & v); // output operator // operators overloaded as member functions M_Vector& operator= ( const M_Vector & v); // assignment const M_Vector operator+ ( const M_Vector & v) const; // vector addition M_Vector operator+= ( const M_Vector & v); // vector addition const M_Vector operator- ( const M_Vector & v) const; // vector subtraction M_Vector operator-= ( const M_Vector & v); // vector subtraction const double operator* ( const M_Vector & v) const; // dot product const M_Vector operator* ( const double & d) const; // scalar multiplication M_Vector operator*= ( const double & d); // scalar multiplication const M_Vector operator/ ( const double & d) const; // scalar division M_Vector operator/= ( const double & d); // scalar division bool operator== (const M_Vector &v) const; // equality bool operator!= (const M_Vector &v) const; // inequality double & operator[]( const int & i ); // subscript private: double *array; // array in which to store vector values int size; // size of the vector }; #endif