Instructions
Practice Problems
Pair programming assignment
Problem 1:   Function objects, sorting
Problem 2:   Function objects, binary search trees
5.3.5

Assignment 6

Goals: Understanding function objects, exceptions.

Instructions

The names of the projects and some of the project files must be exactly the same as specified in the assignment. Failure to do so makes it impossible for the graders to run your submission and results in immediate loss of at least 50% of the homework credit.

Make sure you follow the style guidelines for code indentation.

You will submit this assignment by the deadline using the Web-CAT submission system. We will be practicing its use during the lab next week.

With each homework you will also submit your log file named pairxxx.txt where you replace xxx with your pair number.

On top of every file you submit you will have the names of both partners, and the pair number.

The .txt file will be the log of your work on this assignment. Each log entry will have data and time, who was present (one or both of the partners) and a short comment decribing what you were working on.

There will be a separate submission for each problem - it makes it easier to grade each problem, and to provide you with the feedback for each problem wou work on.

The two submissions will be organized as follows:

Due Date: Tuesday, February 18th, 10:59 pm.

Practice Problems

Work out these problems on your own. Save them in an electronic portfolio, so you can show them to your instructor, review them before the exam, use them as a reference when working on the homework assignments.

Pair programming assignment

Problem 1: Function objects, sorting

Start with your solution to the String problem from the previous homework.

Problem 2: Function objects, binary search trees

You will work with a binary search tree that represents a collection of Book objects. Remember, a binary search tree represents an ordered collection of data where each node holds one data item and has links to two subtrees, such that all data items in the left subtree come before the current data item and all data items in the right subtree coma after the current data item.

The tree with no data is represented as a leaf.

Start a new project and define in it the class that represents a Book as shown in the class diagram below. We want to keep track of the books in seeral different ordered ways - by title, by author, and by price.

The following class diagram should help you.

                 +-----------------------+

                 | abstract class ABST   |

                 +-----------------------+

      +----------| IBookComparator order |

      |          +-----------------------+

      |                 / \

      |                 ---

      |                  |

      |      -----------------

      |      |               |

      |   +------+   +------------+

      |   | Leaf |   | Node       |

      |   +------+   +------------+

      |              | Book data  |--------+

      |              | ABST left  |        |

      |              | ABST right |        |

      |              +------------+        |

      |                                    v

      v                            +---------------+

+-------------------------------+  | Book          |

| IBookComparator               |  +---------------+

+-------------------------------+  | String title  |

| int compare(Book b1, Book b2) |  | String author |

+-------------------------------+  | int price     |

                                   +---------------+