CS 311 Fall 2009  >  Assignment 6

CS 311 Fall 2009
Assignment 6

Assignment 6 is due at 5 p.m. Thursday, November 12. It is worth 25 points.

Procedures

This is a group assignment. Please work in a group of 2 or 3. Each group only needs to turn in a single copy of the assignment. Under normal circumstances, each will receive the same grade on the assignment.

E-mail answers to the exercises below to ffggc@uaf.edu, using the subjectDA6”.

Note: Restrictions on extra public members are lifted, for this assignment. You may include public members in your classes, other than those specifically mentioned below. You may also write additional publicly available global functions. Because of compiler troubles, I recommend that you do NOT declare any friends in this assignment; if some data or functionality needs to be accessible to some other class, instead of making a friend, simply make the appropriate members public.

Exercises (20 pts total)

Exercise A — “Minimalist” Linked List Class Template

Purpose

In this exercise, you will write a Linked List. This will not be a full-featured package. It has those features required for testing, but its primary purpose is to be the basis for Exercise B.

You will also write a function to reverse your Linked List.

Instructions

Implement a C++ class template that manages a Linked List. The type of item in the list should be specified by the client. Be sure to follow the coding standards. All standards apply, with the exception noted above concerning extra public functions.

Exercise B — Stack Template

Purpose

In this exercise, you will write a Stack that uses the Linked List from Exercise A to hold its data.

Instructions

Implement a C++ class template that manages a Stack. The type of item in the Stack should be specified by the client. Be sure to follow the coding standards. All standards apply, with the exception noted above concerning extra public functions.

Notes

About Iterators

Some facts:

Thus, SList::read and SList::write will look something like this.

template <typename T>
class SList {

[ A LOT IS LEFT OUT HERE ]

public:
    template <typename InputIterator>
    void read(InputIterator first, InputIterator last)
    {
        [ CLEAR THE ITEMS IN THE LIST HERE ]
        while (first != last)
        {
            value_type val = *first++;
            [ PUT val INTO THE LIST HERE ]
        }
    }

    template <typename OutputIterator>
    void write(OutputIterator dest) const
    {
        for ( [ ??? ] ) // ITERATE THROUGH LINKED LIST, SOMEHOW)
        {
            value_type val;
            [ HERE, PUT NEXT LIST ITEM INTO VAL ]
            *dest++ = val;
        }
    }
};

About Friendship

Some C++ compilers do not correctly support friends that are templates. Therefore, I strongly suggest that you avoid declaring friends in this assignment.

If you need to give a global function or class access to some other class’s private members, you may, if you wish, make those members public. Thus, the usual requirements for the proper use of “private” are loosened, for this assignment.

Test Program

I have written a single test program for both exercises: da6_test.cpp. If you compile and run your package with this program (unmodified!), then it will test whether your code works properly.

Do not turn in da6_test.cpp.

Because of the single test program, the code for both exercises must at least exist, and must compile with the test program. Code that does not compile at all will not be graded.

Other Thoughts

If you do a good job on Exercise A (the Linked List), then Exercise B (the Stack) should be very easy. In particular, if the Linked List knows how to initialize, copy, and destroy itself properly, then the compiler-written default ctor and Big-Three functions should be fine, for the Stack class. That leaves empty, top, push, and pop, none of which is likely to be very difficult.

For the Linked List class, remember the swap trick for writing copy assignment. Also remember that it is probably easier to put necessary functionality into class SList than to have the Stack manage the internal details of the Linked List.


CS 311 Fall 2009: Assignment 6 / Updated: 7 Nov 2009 / Glenn G. Chappell / ffggc@uaf.edu Valid HTML 4.01!