Comp201: Principles of Object-Oriented Programming I
Spring 2008 -- HW06   


See Assignments Page for due date! Don't forget your new Honor Pledge file!

Save all of your work in a directory called HW06 on your U: drive (Owlnet account) inside a directory called Comp201 .

For all the problems below, you must write a JUnit test class called Test_HW06. Individual problems should be tested using separate methods of that class. Be sure to test completely!

Cautions

Note: some problems may require that you write "helper" visitors.
  1. (50 pts total) Do the 4 list visitor problems in lab07.
    1. (10 pts) Exercise 1.
    2. (10 pts) Exercise 2.
    3. (10 pts) Exercise 3.
    4. (20 pts) Exercise 4.

  2. (10 pts) Write a visitor called SumOfSq to compute and return the sum of squares of a list that contains Integers.

  3. (10 pts) Write a visitor called Reverse to compute and return a list that is the host list in reverse order.

  4. (10 pts) Write a visitor called LastElement to find and return the last element of the host. Do this by traversing the host only once.

  5. (15 pts) Write a visitor called FoldR that has the same behavior as the foldr methods you wrote for HW05 prob. 7. Your visitor should take the same IFoldInp interface as its input parameter. Your test code should demonstrate that your SumList, MultList, and CopyList classes all work unmodified with your FoldR visitor.

  6. (20 pts extra credit) In the same vein as FoldR, write a visitor calle FoldL ("fold-left") that processes a list using an IFoldInp but in a forward accumulation manner. Your test code should show that your unmodified SumList and MultList give the same results as when used with FoldR (why?) but that CopyList returns the reverse of the list (why?). Hint: Look at your Interpreter pattern reverse accumulation algorithms and compare them with your FoldR visitor. Then look at your Interpreter pattern forward accumulation algorithms and try to see what FoldL must therefore be like.

  7. (20 pts) Write a visitor called Zip to weave the host list with an input list in such a way that the elements in the resulting list alternate between the elements in the host list and the elements in the input list. For example, when we Zip (1 2) with (6 7 8), we get (1 6 2 7 8). Notice the lists need not have the same length. Hint: if (1 6 2 7 8) is the zip of (1 2) and (6 7 8) then what is (6 2 7 8) in terms of zip?

 

115 points total + 20 pts extra credit.

 

When you have completed your homework, zip up the entire HW06 directory and submit the zipped file using the file upload link on the Assignments Page.


Last Revised Thursday, 03-Jun-2010 09:50:22 CDT

©2008 Stephen Wong and Dung Nguyen