1
h05
CS24 S17
Name:
(as it would appear on official course roster)
Umail address: @umail.ucsb.edu section
Optional: name you wish to be called
if different from name above.
Optional: name of "homework buddy"
(leaving this blank signifies "I worked alone"

h05: Chapter 6, sections 6.1-6.6

ready? assigned due points
true Wed 05/10 05:00PM Wed 05/24 05:00PM

You may collaborate on this homework with AT MOST one person, an optional "homework buddy".

MAY ONLY BE TURNED IN IN THE LECTURE/LAB LISTED ABOVE AS THE DUE DATE,
OR IF APPLICABLE, SUBMITTED ON GRADESCOPE. There is NO MAKEUP for missed assignments;
in place of that, we drop the three lowest scores (if you have zeros, those are the three lowest scores.)


Please:

  • No Staples.
  • No Paperclips.
  • No folded down corners.

Complete your reading of Chapter 6, section 6.1 -6.2, 6.3 (ignore references to multiset of page 139), 6.4-6.6 (If you don’t have a copy of the textbook yet, there is one on reserve at the library under “COMP000-STAFF - Permanent Reserve”).

    1. (10 pts) Write a template function named IsEqual() that compares two items and returns a boolean. If the items are equal the function should return true otherwise it should return false. The function has two parameters of the same type. The type may be any type that has a copy constructor and the == operator defined.
    2. (10 pts) Re-read pages 314-315. Then consider the Words class from lab03. Convert the words class to a template class that can be used to store a collection of any datatype instead of just std::string. Write the new definition of the Words class below. You don't have to implement the methods
    4. (10 pts) Rewrite your definition of your Words class from the previous question to support a forward iterator. You must include a new iterator data type that is typedef-ed to 'iterator'. Provide an inline implementation of the begin() and end() methods that return iterators to the first element of the Words class and one past the last element, respectively (just like we did in lecture). You must also write a new forward iterator class with inline implementation of all methods that are supposed to be supported by forward iterators.
    5. (10 pts) Write code that uses your template Words class with a forward iterator (from the previous question). Your code should declare an object of type Words named intBag to store a collection of integers (instead of strings). Store three integers into 'intBag' using the append() method. Declare and initialize an iterator to intBag and write a loop to print all of the elements of the collection using the iterator.