Course Home | Homework | Lab Open Hours | Programming | Schedule & Lecture Notes | Submit

Saint Louis University

Computer Science 180
Data Structures

Michael Goldwasser

Spring 2007

Dept. of Math & Computer Science

Programming Assignment 03
Fancy Vector

Due: Wednesday, 21 February 2007, 8pm

Please see the general programming webpage for details about the programming environment for this course, guidelines for programming style, and details on electronic submission of assignments.

The files you may need for this assignment can be downloaded here.

Collaboration Policy

For this assignment, you must work individually in regard to the design and implementation of your project.

Please make sure you adhere to the policies on academic integrity in this regard.


Contents:


Overview

Inspired by some of the convenient behaviors supported by Python's lists (the analog of the C++ vector), our goal in this assignment is to start with the simple vector implementation given in Chapters 4.3-4.4 of the KW text and to add some additional behaviors.

Specifically we want you to implement five new methods with the following signatures:

    /** Determines whether the given value is contained in the vector.
     *  @param val   The value
     *  @return true if contained, false otherwise
     */
    bool contains(const Item_Type& val) const;

    /** Determines the number of occurrences of given value.
     *  @param val  The value
     *  @return the number of occurrences
     */
    size_t count(const Item_Type& val) const;

    /** Determines the first index at which give value occurs (if any).
     *  @param val  The value
     *  @return the first index, if found;  otherwise returns size (clearly an invalid index)
     */
    size_t index(const Item_Type& val) const;

    /** Removes all occurrences of given value (if any).
     *  @param val  The value
     *
     * Note:  this is difference semantics than Python's remove.
     */
    void remove(const Item_Type& val);

    /** Reverse the contents of the vector.
     */
    void reverse();
If you prefer, here is a prettier version of this documentation as generated via Doxygen, based upon the documentation embedded in the above code.

Your program will be tested in accordance with these specifications, so please make sure that you understand the precise semantics.


Files We Are Providing

All such files can be downloaded here.


Use of the Driver

test_vector is a text-based, menu-driven program for testing your vector implementation. The menu allows you to call any combination of supported behaviors, including the original ones provided by KW and the five new methods you are implementing.

The menu options are as follows:

(At)  at(i)
(As)  at(i) = val
(Ci)  contains(val)
(Cu)  count(val)
(Em)  empty()
(Er)  erase(i)
(Ix)  index(val)
(In)  insert(i,val)
(N)   new (empty) vector
(O)   output
(Po)  pop_back()
(Pu)  push_back(val)
(Rm)  remove(val)
(Rv)  reverse()
(Sz)  size()
(Q)   Quit
where parameters i and val are specified, when necessary through a secondary prompt. The driver will automatically report the return value it receives from your code, or to report any exceptions that were raised.

By default, the program takes input from the keyboard. However the driver has an optional feature which allows it to read input from a file rather than from a keyboard. The file should have the identical characters which you would use if you were typing them yourself on the keyboard. This feature simply allows you to test and retest your program on a particular input without having to retype the input each time you want to run the program. It is also convenient at times when running with a debugger to have the input read from a file rather than from the keyboard. If the program reaches the end of the file without exiting, then it will revert back to reading input from the keyboard for the remainder of the program.

To use this feature, you must specify the exact filename (including any suffix), as a single argument at runtime. Details on how to provide such arguments are given in the general programming webpage.

Here is a sample input file, appropriately formatted.


Black-Box, Unit Testing

Part of developing good software is also knowing how to perform meaningful testing of your or another programmer's software. Chapter 2.3 of the text discusses formal approaches to testing a program. You may wish to read that section for inspiration.

For this assignment, you will be submitting input which will be used as a test case, not only for your own program, but for every student's program. Formally, we will be using what is termed, black-box, unit testing. We say this is unit-testing because our driver lets you make individual calls to the public methods supported by the vector class (rather than testing the overall performance of a larger applications which uses vectors).

We say this is black-box testing because you will be designing a test for source code which you have never seen. Often, testing is performed in close coordination with an examination of source code. For example, we may write some code or view some code, and then try to test that particular chunk of code. There is an inherent danger in relying only on such tests. In particular, if the tests are based on the same flow of thoughts as (errant) code, we are more likely to forget to test for a particular combination of events that were not considered by the code. The practice of "black box" testing is to design a set of tests based purely on the formal specifications for a data structure, but without actually seeing the source code.

For this assignment, your tests must be specified as a plain text file which adheres strictly to the file format which is expected by the text-based driver, test_vector, described earlier. You do not need to provide any summary of the "correct" responses for these tests. We will automatically compare the output of each student's implementation against a reference output created by the instructors (correct) implementation. Because our execution of student tests will be automated, we strongly recommend that you run your program on your inputfile to make sure it is accepted by the driver.

Your file may use at most 100 commands. If your input file contains more than the prescribed number of commands, we will simply truncate the test.


Files to Submit


Grading Standards

The assignment is worth 10 points. Eight points will be awarded based on our own evaluation of your assignment and the readme file. One additional point will be awarded fractionally based on how well your program performs on other students' test inputs. The final point will be awarded fractionally based on how well your test input fools other students' flawed programs.


Michael Goldwasser
CSCI 180, Spring 2007
Last modified: Friday, 16 February 2007
Course Home | Homework | Lab Open Hours | Programming | Schedule & Lecture Notes | Submit