The power of C++ is that we can program and define our own classes, and they will work just like int, float and double! Two very simple, but handy classes that we shall make for ourselves are i3vec and d3vec for three-vectors of integers and doubles, respectively.
The code for these classes appears in Appendix B. Note that each object of these classes has three members, x, y, and z, so that for a given vector ``v'', we can access its components as ``v.x'', ``v.y'' and ``v.z''. These two classes are so simple that we actually do not have to provide much code. We, however, do provide our own, handy constructors so that ``i3vec(1,2,3)'' and ``d3vec(2.,4.,5.) construct the appropriate three-vectors.
Compile and check that the program ``vec.C'' in Appendix B runs. Next, write a subroutine with the prototype
which returns a double vector whose components are just the variable s times each of the components of i. Finally, uncomment the statement ``dv=scalarmult(3.,iv);'' in ``vec.C'' and verify that its output is correct.d3vec scalarmult(double s,i3vec i);