16.11 Assignments

Questions

1. What is meant by the term generic software?

2. What new keyword is used in standard Generic Modula-2, and in what contexts is it used?

3. What are the four new kinds of compilation units in Generic Modula-2?

4. What are the three kinds of refining modules in Generic Modula-2?

5. Describe the kinds of formal parameters used in Generic Separate modules.

6. What actual parameters are compatible with these formal parameters?

7. Why are variables not permitted as actual parameters in refining modules when they are allowed for formal value parameters in procedures?

8. "The reserved word TYPE is re-used in Generic modula-2 as though it were a pervasive." Explain this statement.

9. If Generic Modula-2 were implemented with a program that simply read a refining module and then created a copy for compilation of the appriopriate generic separate module without the parameters but with a few lines renaming the formal parameters as the actual ones in the style of section 16.1.1, what differences would there be between this and an implementation that evaluated the actual parameters and did the substitution as part of the compilation process without creating a copy?

10. The generic module Lists in section 16.7 has a bare minimum of comments. Study the code carefully and comment it in detail.

11. Give a detailed description of generics in at least two other computing languages and compare both to each other and to Modula-2.

12. Name at least four programs either from the examples in the book or from the assignments you have done that would not be appropriate as generic separate modules. Explain why in detail.

13. Discuss ways in which Standard Generic Modula-2 might eliminate the need for variant records. Or, does it?

14. In what ways is refining locally different from refining separately?

15. What additional functionality does the ability to refine locally provide that cannot be had by refining separately only?

16. What can a local refining module have that a separate refining module cannot have?

Problems

17. Consider the module ArithSeq in section 3.8. Rewrite this module so as to be generic for the data in the sequence and test your code with a client that imports a refinement.

18. Consider the module SortThree in section 4.3. Rewrite this module so as to be generic for the data to be sorted and test your code with a client that imports a refinement.

19. Consider the module Points in section 6.9. Rewrite this module so as to be generic for the data in the ordered pair and test your code with a client that imports a refinement.

20. Consider the module PointToPoint in section 6.9. Rewrite this module so as to be generic for the data in the sequence and to have all the facilities of the module Points also available for export and then and test your code with a client that imports a refinement.

21. Consider the module Vectors in section 7.11. Rewrite this module so as to be generic for the data in the components and test your code with a client that imports a refinement. 22. Produce and test a generic insert sort.

23. Produce and test a generic shell sort.

24. Produce and test a generic merge sort.

25. Produce and test a generic heapsort.

26. Produce and test a refinement of a sort that can sort an array of your favourite type of records.

27. Test by using a refinement of the generic module Lists in section 16.7.1.

28. Complete and test the simple generic separate module Stacks in section 16.2.1 and test your code with a client that imports a refinement.

29. Complete and test the simple generic separate module Matrix in section 16.2.1 and test your code with a client that imports a refinement. You will need to add some simple matrix manipulation procedures as you deem appropriate.

30. Complete and test the simple generic separate module Sorts in section 16.2.1 and test your code with a client that imports a refinement.

31. Complete and test the simple generic separate module Counter in section 16.2.1 and test your code with a client that imports a couple of refinements.

32. Provide and test the implementation part of the generic module Queues in section 16.7.2.

33. Provide and test the implementation part of the generic module Stacks in section 16.7.3.

34. Design, implement, and test a generic binary tree ADT.

35. From the last question, create, using refinement, a balanced binary tree.

36. Complete and test the simple generic separate module ListsSorted and the refinement IntListsSorted in section 16.6 and test your code. You may make use of the generic list module in that same section, or another one elsewhere in the chapter.

37. Complete and test the simple generic separate module PriorityQueues and the refinement StudentPriorityQueues in section 16.6 and test your code. You may make use of the generic queue module in that same section, or another one elsewhere in the chapter.

38. Refine and test the generic module Lists in section 16.7.1.

39. Design, implement, and test a two way list ADT. Can you base it on the above module Lists? Why or why not?

40. Design, implement, and test a circular list ADT. Can you base it on the above module Lists? What about on the two way list? Why or why not?

41. Complete, refine and test the generic module Queues in section 16.7.2.

42. Complete, refine and test the generic module Stacks in section 16.7.3.

43. Pretend that yor implementation lacks the standard generic Modula-2 extensions. (You may not need to pretend.) Write a program that will take as input a file containing only a refining separate module (implementation or definition) and find and refine the appropriate generic separate module (text file) using renaming as in section 16.1.1.

Challenges

44. Add to the code in the last question the ability to refine as a local module.

45. Redesign, implement, and test the statistics modules in section 7.7 so as to take advantage of generics. Show your design to your instructor before producing code. Among several other things, your modules should work for both real types.

46. Gather several of your generic sorting techniques into a single module. Make a new such module, but with the comparison procedure type having reference semantics rather than the value semantics employed in most such routines. Can the choice of semantics also be made generic? Why or why not?

47. Design, implement, and test a generic table ADT. Show your design to your instructor before producing code.

48. Design, implement, and test a generic B-tree ADT.


Contents