Due 2:00 AM, Friday, 17 February 2017
There are three things that happen as you get older. The first is that your memory goes. I forget the other two. (I may have said this in class, but I can't be sure.)
Businesses often cater to the frailty of our memories by providing mnemonics for their telephone numbers. For example, you can call United Parcel Services at 800-PICK-UPS - which actually has two reinforcing meanings.
In the old days, you would often call the operator to get phone information.
In this assignment you will implement a program to find a word that corresponds to a given positive integer, as well as convert a word to its corresponding phone number.
Callme (digits | letters) [-debug]? [-file filename]?that processes the command line arguments as follows:
All error output (usage and "Fatal Error" messages below) should be printed to standard error. For example,
fprintf(stderr, "usage ...");All other output should be printed to standard output. (Use normal printf.) Examples:
% Callme usage: Callme (digits | letters) [-debug]? [-file filename]? % Callme pickups alphabetic: pickups => 7425877 % Callme 7425877 numeric: 7425877 => pickups % Callme 7245677 numeric: 7245677 => sailors schloss % Callme 7245677 -debug Loading dictionary: /usr/share/dict/words Growing to size: 2048. n: 1024. Used buckets: 812. Occupancy rate: 0.79 Growing to size: 4096. n: 2048. Used buckets: 1611. Occupancy rate: 0.79 Growing to size: 8192. n: 4096. Used buckets: 3219. Occupancy rate: 0.79 Growing to size: 16384. n: 8192. Used buckets: 6438. Occupancy rate: 0.79 Growing to size: 32768. n: 16384. Used buckets: 12921. Occupancy rate: 0.79 Growing to size: 65536. n: 32768. Used buckets: 25899. Occupancy rate: 0.79 Word Count: 50403 numeric: 7245677 => sailors schloss % Callme 7245677 -debug -file words Loading dictionary: words Growing to size: 2048. n: 1024. Used buckets: 812. Occupancy rate: 0.79 Growing to size: 4096. n: 2048. Used buckets: 1611. Occupancy rate: 0.79 Growing to size: 8192. n: 4096. Used buckets: 3219. Occupancy rate: 0.79 Growing to size: 16384. n: 8192. Used buckets: 6438. Occupancy rate: 0.79 Growing to size: 32768. n: 16384. Used buckets: 12921. Occupancy rate: 0.79 Growing to size: 65536. n: 32768. Used buckets: 25899. Occupancy rate: 0.79 Word Count: 50403 numeric: 7245677 => sailors schloss % Callme sailors -debug alphabetic: sailors => 7245677 % Callme 4444444 numeric: 4444444 => ** no matches ** % Callme givemeheaven alphabetic: givemeheaven => 448363432836Callme should:
#define INITIAL_SIZE (1024) #define GROWTH_FACTOR (2) #define MAX_LOAD_FACTOR (1)The initial size of the hash table should be 1024 buckets. The hash table keeps track of how many elements it contains, say n. Once n * MAX_LOAD_FACTOR == SIZE, then the table expands. The size of the new table will be SIZE * GROWTH_FACTOR.
The table also keeps track of how many buckets are used - that is, do not contain the NULL pointer. If the -debug flag is on, the following message from hash.c will be printed to standard output every time the table expands:
Growing to size: 2048. n: 1024. Used buckets: 790. Occupancy rate: 0.77where
Loading dictionary: /usr/share/dict/words // name of dictionary file Word Count: 50403 // how many words got copied to the hashtable.
Also, if the command line argument is a word instead of a number, -debug has no effect. The dictionary should not be loaded and the hashtable is not created, much less expanded.
YOU MUST SUBMIT YOUR FILES (INCLUDING THE LOG FILE) AT THE END OF ANY SESSION WHERE YOU SPEND AT LEAST ONE-HALF HOUR WRITING OR DEBUGGING CODE, AND AT LEAST ONCE EVERY HOUR DURING LONGER SESSIONS. (All submissions are retained.)
% /c/cs223/hw3/Tests/test.CallmeUnlike the previous assignment, Callme does not read standard input. It reads command line arguments. You can look at the test files to see how a specific test works. You may invoke a given test as follows:
% /c/cs223/hw3/Tests/test.Callme 01(you may specify more than one test here).
If your output looks the same as what is expected, but your program still fails the test, there are probably some invisible characters in your output.
ESTIMATE of time to complete assignment: 10 hours Time Time Date Started Spent Work completed ---- ------- ---- -------------- 1/13 10:15pm 0:45 Read assignment and relevant material in K&R 1/16 4:45pm 1:15 Sketched solution using a finite-state machine with one-character look-ahead 1/19 9:00am 2:20 Wrote the program and eliminated compile-time errors; code passes eight tests 1/20 7:05pm 2:00 Discovered and corrected two logical errors; code now passes eleven tests 1/23 11:00am 1:35 Finished debugging; program passes all public tests ---- 7:55 TOTAL time spent I discussed my solution with: Peter Salovey, Ben Polak, Tamar Gendler, and Jonathan Holloway (and watched four episodes of The Simpsons). *A brief discussion of the major difficulties encountered*but MUST contain
N.B. To facilitate analysis, the log file MUST be the only file submitted whose name contains the string "log" and the estimate / total MUST be on the only line in that file that contains the string "ESTIMATE" / "TOTAL".
% /c/cs223/bin/submit 3 Makefile Callme.c hash.c hash.h time.logsubmits the named source files as your solution to Homework #3;
% /c/cs223/bin/check 3lists the files that you submitted for Homework #2;
% /c/cs223/bin/unsubmit 3 error.submit bogus.solutiondeletes the named files that you submitted previously for Homework #3 (which is useful if you rename a file or accidentally submit the wrong one);
% /c/cs223/bin/makeit 4 Callmeruns "make" on the files that you submitted previously for Homework #4;
% /c/cs223/bin/testit 5 Callmeruns the public test script for Callme using the files that you submitted previously for Homework #5; This might not be working. Use the testing instructions given above.
% /c/cs223/bin/protect 6 Callme.c time.logprotects the named files that you submitted previously for Homework #6 (so they cannot be deleted accidentally);
% /c/cs223/bin/unprotect 7 util.c time.logunprotects the named files that you submitted previously for Homework #7 (so they can be deleted); and
% /c/cs223/bin/retrieve 8 common.c time.logand
% /c/cs223/bin/retrieve 8 -d"2017/01/21 20:00" util.cretrieve copies of the named files that you submitted previously for Homework #8 (in case you accidentally delete your own copies). The day and hour are optional and request the latest submission prior to that time (see the -d flag under "man co" for how to specify times).
When assignments are style graded, EVERY source file found in the submit directory will be reviewed. Thus prudence suggests using unsubmit to remove a file from the directory when you change its name or it ceases to be part of your solution. See http://zoo.cs.yale.edu/classes/cs223/doc/Style
Prudence (and a 5-point penalty for code that does not make) suggests that you run makeit ("makeit 2 Callme") after you have submitted the final version of your source files. Better yet, run testit ("testit 2 Callme").