CS1321 Homework 4i1

Jeffrey D. Oldham


Date: 2000 Feb 27


Contents



This homework is optional and not for credit. It will not be graded and need not be submitted. It is strongly recommended, however, that you do the homework anyway to get additional practice in defining a C++ class since defining C++ classes is an important skill.

Reading

Start reading chapter 4.

Problem Statement

You are to implement a class for mathematical vectors, as discussed in class. In mathematics, a vector is an n-tuple of real numbers, which we could write as (x1...xn). n is called the length of the vector. Many operations are defined on vectors including the following.

The objective in this assignment is to define a C++ class MVector to represent mathematical vectors. Here is an example of using this class. Our strategy for implementing MVector is to represent a mathematical vector by a C++ STL vector of doubles. We will need to write functions to support the following operations on MVector objects (using syntax as illustrated in the example).

We also need to define a type size_type.

What Files Do I Need?

There is one essential file and one recommended file.

To use the code, write a .cc file containing a main function definition. Be sure to #include "mvector.h" and put the file in the same directory as mvector.h. Then compile the .cc file. For example,

g++ -Wall -pedantic mvector-use.cc -o mvector-use

Testing

You are encouraged to test your code thoroughly with the example-use program (mvector-use.cc), which you may want to extend with additional tests. As currently written, this program will not compile unless you implement all the desired MVector functions. If you want to implement and test functions a few at a time, you can do so by commenting out the parts of mvector-use.cc that test functions you have not yet implemented.



Footnotes

... Homework 4i1
©2000 Jeffrey D. Oldham . All rights reserved. This document may not be redistributed in any form without the express permission of the author.



2000-02-27