Com S 228 --- Introduction to Data Structures HOMEWORK 4: Control Abstraction (continued) Modules and Information Hiding (File $Date: 1995/02/11 23:08:57 $) Due: problem 1, at the beginning of your discussion section week of Feb. 16; problem 8, at the beginning of class on Feb 20. (You'll also want to look at problem 8 before your discussion section on Feb. 16.) In this homework, you will learn about top-down design, modules, and information hiding. The readings are in the section headings below. Problems 1-3 are on top-down design. Problem 4 is on recursion (which you should not use in any other problems). Problems 5 and 6 are to aid your readings of the modules chapter, and problem 7 is about writing a client program using modules. PLEASE NOTE: For each programming problem, hand in a printout of your code files, and your transcript of testing. Your transcript must be run on the Com S department machines (use the Unix command ``script''); it should show your testing. Your transcript and each file you print should have the file name and your information (your ~/.me file as in HW0) at the top as comments. You should use comments as we are doing in class (see /home/cs228/public/assertion-notation.txt for details). We will be grading on these comments now. For additional practice, we suggest that for at least some of the problems, you write out a solution on paper first. This is more like what the test will be. When you are happy with your paper version, try it on the computer. (Note that you must hand in a printout and a transcript, however.) HEADINGTON & RILEY: 1.3-4, Appendix D /home/cs228/public/doc/assertion-notation.txt 1. (50 points) Design a program to solve the problem posed in Headington and Riley's programming project 1.4 on pages 55-56. The design should be documented by PRE, MODIFIES, and POST comments for the main program, and for each helping function, as we did for the sorting problem discussed in class (see files in /home/cs228/public/examples/selsort). You must also write stubs for each module, and do top-down testing (see p. 40-41) as we did in class. Hand in a printout of your testing and the C++ files (with stubs, not refined code). In your discussion section, you'll discuss your solution with another class member, and will have an opportunity to ask questions and discuss solutions with the class as a whole. So be sure to write your design clearly. We won't check the details of your work, as that will be the subject of the discussion. So don't worry (too much) if it isn't exactly right. We will check that what you hand in has the right parts (a printout of each file, labeled correctly with comments at the top, and a transcript). 2. (suggested practice) Finish the implementation of programming problem 1.4 on pages 55-56 of Headington and Riley. 3. (30 points extra credit) Do problem 4.23 on page 260 of Deitel and Deitel's book (turtle graphics) 4. (suggested practice) If you didn't take Com S 227, you might want some practice with recursion. You might try exercises 4.32, 4.34, in Deitel and Deitel's book. HEADINGTON & RILEY: 2 5. (suggested practice) Do some of the exercises in Headington and Riley's book for chapter 2 (pp. 99-105). I suggest exercises 2.1(a,b), 2.2, 2.3(a), 2.4(b), 2.6(a), 2.7(a), 2.8(a,c,e), 2.9(a,e), 2.10(a), 2.12. Do what parts seem useful to you, then look at the answers, which are at the end of the book, in pages A-172 to A-173. DEITEL & DEITEL: 3.10-11, 18.5, 17.1-3, 17.5 6. (suggested practice) Do some of the exercises in the self-review section on pages 196-197 of Deitel & Deitel's book. I suggest working exercises 3.2, 3.4, 3.5 on paper. Do what parts seem useful to you, then look at the answers, which follow the self review section on pages 198-199. 7. (suggested practice) Do some of the exercises in the self-review section on pages 811-812 of Deitel & Deitel's book. I suggest working exercises 17.1(a-d,f,g,h,i) on paper. Do what parts seem useful to you, then look at the answers, which follow the self review section on page 812. HEADINGTON & RILEY: 2 8. (80 points) (Time estimate: 4 hours, including top-down testing) Do programming project 2.2 in Headington and Riley's book, page 106. We refine the requirements there by stating that: SetPassword must prompt the user for a seed for the random number generator. If the entered number for the seed is not positive, the user should continue to be prompted, until a positive number is entered. The password chosen should consist of only nonblank printing characters (ones with ASCII codes 33-126, in decimal). You may also assume that the user only types integers when prompted for a positive integer, but the user may type negative integers. (You may thus ignore the possibility of end-of-file or other errors on cin.) For this problem, there is a script file giving test output in the file /home/cs228/public/homework/hw4-8-typescript.txt You should run these test cases, as well as any additional ones you think are needed to properly test (or to debug) your program. You'll find the code you need in the directory /home/cs228/public/HR (These are edited to conform to the documentation standards of the class; exact text from the book's diskette can also be found on-line.) Be sure to add your name information to the password.h and password.C files. You can add it after to lines of comment already in the file. You are required to submit a makefile (named "Makefile") with this problem. Your test script should show how your makefile is used to compile your program on Unix, using the header files in the directory (for rand.h) /home/cs228/public/include and the library in the file /home/cs228/public/lib/libcs228.a for the compiled rand.o file. (You should *not* hand in a printout of, or change, rand.h and rand.C.) When you compile use the flag -I/home/cs228/public/include to tell the compiler to look in /home/cs228/public/include for rand.h. Also when you use the compiler to link, use the flags -L/home/cs228/public/lib -lcs228 at the end of the line to tell the compiler where to find the library with the compiled object for rand.o. If you want to develop on a home system, copy the relevant files from the directory /home/cs228/public/HR. Hints: pay attention to the treatment of '\n' and '\0' in the book. Strings in C++ end with a '\0' character, otherwise they don't work right. You may, and are encouraged to, create other modules and functions for this program. You might want to use top-down design and testing too (hint, hint). 9. (10 points extra credit) Make your program for problem 8 so that it can handle formatting errors and end-of-file on cin. Make any decisions about the requirements for the program you feel are reasonable to deal with such errors. Add any additional test cases you believe are necessary.