CS 24, Fall 2016

Programming Assignment 2

Due: Sunday, October 16, 11:59pm
Worth: 100 points

PA2 can be done either in two-people teams or individually.

If you are working with a partner, don't just split up the work! Pair programming means working together to solve each of the problems: trust us that it will work more smoothly for you if you do it like that anyway. Also be sure that both partners' names are in a comment at the top of the source code file, and that you properly form a group for this project in the submit.cs system.

  1. Implement the class sequence from Figure 3.9 on page 129 of the textbook. Your implementation must be in a new file that you create named sequence1.cxx.
    • Type your name(s) and the date in a comment at the top of sequence1.cxx. [Last reminder?]
    • Your basic job is to implement each of the member functions (including the constructor) of class sequence - as they are defined in the class header file: sequence1.h - first download a copy of this header file, and store it in your working directory for this project.
    • Be sure to #include sequence1.h in your implementation file.
    • Useful tips from Michael Main (textbook author):
      • Many of the features of this class are similar to the Bag class from Section 3.1, so start by throughly reading Section 3.1 and pay attention to new features such as static constant members and the use of a typedef. The sequence class itself is discussed in Section 3.2 of the class text. Notice how the sequence differs from a Bag.
      • Write the invariant of your ADT at the top of sequence1.cxx. The invariant describes precisely how all of your private member variables are used. All of the member functions (except for the constructor) may count on the invariant being true when the member function is activated. And all of the member functions are responsible for ensuring that the invariant is true when the function returns.
      • As always, do your work in small pieces. For example, my first version of the sequence had only a constructor, start, insert, advance, and current. My other member functions started out as stubs.
  2. Compile and test your program at CSIL, using this interactive test program: sequence_test.cxx (download to your working directory). It is exactly the same program discussed in section 3.3 of the textbook - read about it there. You can use the following command to compile it along with your implementation:
    g++ -o sequence_test sequence_test.cxx sequence1.cxx
    The point of this interactive test program is for you to test your functions individually, to make sure each one is working properly before running your implementation through more comprehensive tests like the ones that will be used when you submit. To learn details of those tests, see the non-interactive test program we will use: sequence_exam.cxx (you can try it out before submitting if you want - give 1 or 2 or 3 as a command line argument if you run it).
  3. Submit PA2 at https://submit.cs.ucsb.edu/, or use the following command from a CS terminal:
    ~submit/submit -p 554 sequence1.cxx
    Be sure to wait for the results of the three tests. If you score 100/100 and you've followed all of the other rules, then you'll earn full credit.

Updated 10/4/2016, by Michael Costanzo.
Special thanks to Michael Main, University of Colorado, creator of most parts of this project.