Lab 5 - Template Exercises


Due: Midnight, Wed. June 24, if you are not done in class that date.

Do the following:

  1. Convert the original sequence class with a static array to a template class. You may use your version of the sequence class to do this or copy our version. Our version (sequence1.h, sequence1.C) along with an exam program for the template class (sequence_ex4.C) is in the directory:
       /usr/local/apache2/htdocs/u/csgs/sab/2440/Assignments/labs_S_04/lab5/*.[Ch]
    
    Name the template header file sequence4.h and the implementation file sequence4.template. See p.288 of your text for a summary of the steps required to convert a class to a template class. Note that the exam program was actually written to work with the linked list version of the sequence, and in order to make it work with the version we are doing you need to increase the capacity of your sequence (this is done is sequence4.h) in order for it to pass the exam. I think a capacity of 200 will work.

  2. Using the template sequence class you just created, write a short program (problem2.C) to read 10 strings into a sequence and then print out the strings. Then read 10 integers into a sequence and then print out the numbers.

  3. Using the multiset from the Standard Template Library (see p.765 of your text), write a short program (problem3.C) to read 10 strings into a multiset and then print out the strings using an iterator. Then read 10 integers into a multiset and then print out the numbers using an iterator. See section 6.3, in particular p. 295, for a discussion on using iterators.

  4. Leave sequence4.template, sequence4.h, problem2.C, and problem3.C in your lab5 directory.