CS 1321 (Principles of Algorithm Design II):
Homework #4i

Assigned:
February 25, 2000
Due:
March 15, 2000, at start of class (if submitted)
Credit:
Up to 10 points extra credit

Preliminary remarks

This homework is optional. You need not submit anything, although you are strongly encouraged to attempt the assignment anyway to get additional practice in defining C++ classes, since defining C++ classes will likely figure heavily in the next exam. If you do choose to submit something, you can earn up to 10 points of extra credit, to be added to your homework score.

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.

What to submit

If you choose to turn in this assignment, turn in your completed mvector.h. You need not send any other files. See the guidelines for programming assignments for instructions on how to e-mail the programs. For this assignment use a subject line of ``cs1321 homework 4i''.