VectorN (3D) example program


// N-dimensional vectors using templates

// Some common definitions and declarations

#include <stream.h>
#include "VectorN.h"

const unsigned D = 3; // 3D vectors

int main( int argc, char **argv )
{
   double v1[D] = {1.0,1.5,4.0};
   double v2[D] = {-2.0,3.5,-1.0};

// Construct some vectors

   Vector<D> c1 = Vector<D>(v1);
   Vector<D> c2 = Vector<D>(v2);

// Do some vector arithmetic using the familiar operators
// and construct a result vector c3

   Vector<D> c3 = c1 + c2;

// Print the result

   cout << c1 << " + " << c2 << " = " << c3 << endl;

   return 0;

}


Output:
(1,1.5,4) + (-2,3.5,-1) = (-1,5,3)