|
|
|
|
|
|
|
4. In Chapter 12, we introduced the list informally as an abstract data type. Design, implement, and test a class named IntList. Each IntList object is an unordered list of up to 100 int values. (Recall that an unordered list is one whose components are not assumed to be arranged in order of value.) Include at least the following operations: |
|
|
|
 |
|
|
|
|
Create an initially empty list. |
|
|
|
 |
|
|
|
|
Report whether the list is empty (TRUE or FALSE). |
|
|
|
 |
|
|
|
|
Report whether the list is full (TRUE or FALSE). |
|
|
|
 |
|
|
|
|
Insert a specified integer into the list. |
|
|
|
 |
|
|
|
|
Delete a specified integer from the list. |
|
|
|
 |
|
|
|
|
Search for a specified integer, returning TRUE or FALSE according to whether the item is present in the list. |
|
|
|
 |
|
|
|
|
Sort the list into ascending order. |
|
|
|
 |
|
|
|
|
Output all the items in the list. |
|
|
|
 |
|
|
|
|
Think carefully as you choose a precondition for each operation. For example, the precondition for the Delete operation should be that the list is not empty. Fortunately, the client can check this precondition by first invoking the operation that reports whether the list is empty. You should also decide whether it is allowed to delete a nonexistent integer from the list. If it is allowed, the Delete operation should silently have no effect (and the postcondition should make this clear to the user). If it is not allowed, you should say so in the precondition. The burden of error checking is then on the caller, not on the Delete operation. |
|
|
|
 |
|
|
|
|
For the concrete data representation of IntList, you might consider using two items: a 100-element int array to hold the list items, and a simple variable that stores the current length of the list. |
|
|
|
|
|
|
|
|
5. Modify Programming Problem 4 by creating an ordered integer list class, OrdIntList. Keep the list in ascending order at all times when inserting and deleting items. Remove the Sort operation; it is no longer necessary. Notice that the algorithms for inserting, deleting, and searching are now different from those in Programming Problem 4. You may want to review the discussions of these operations in Chapter 12. |
|
|
|
|
|
|
|
|
1. Classify each of the eight member functions of the DateType class as a constructor, a transformer, or an observer operation. |
|
|
|
|
|
|
|
|
2. a. Design the data sets necessary to thoroughly test the ComparedTo function of the DateType class. |
|
|
|
 |
|
|
|
|
b. Write a driver and test the ComparedTo function using your test data. |
|
|
|
|
|
|
|
|
3. a. Design the data sets necessary to thoroughly test the Increment function of the DateType class. |
|
|
|
 |
|
|
|
|
b. Write a driver and test the Increment function using your test data. |
|
|
|
|
|