CPSC 223: Homework 3. Call Me - mnemonic phone numbers

Due 2:00 AM, Friday, 17 February 2017

P R E L I M I N A R Y S P E C I F I C A T I O N

REMINDER: Do not under any circumstances copy another student's code or give a copy of your code to another student. After discussing the assignment with another student, you may not take any written or electronic record away. Moreover, you must engage in a full hour of mind-numbing activity before you work on it again. Such discussions must be noted in your log file.

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.

Reading

Program Specification

(40) Write a program "Callme" that processes command line arguments specifying the number to encode as a word or the word to convert to a number. Write a program
  Callme (digits | letters) [-debug]? [-file filename]?
that processes the command line arguments as follows: The arguments must appear in the order specified.

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 => 448363432836


Callme should: Note that Callme does NOT load the entire dictionary -- only words equal to the length of the input number. It does not load words that contain non-alpha characters. Callme should convert the word to lowercase before adding it to the hash table, and avoid adding the same word twice.

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.

Use the submit command (see below) to turn in the source file(s) for Callme (e.g., Callme.c, hash.c, hash.h), a Makefile, and your log file (see below).

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.)

Notes

  1. When available, the public grading script will be /c/cs223/hw3/Tests/test.Callme (and my solution will be /c/cs223/hw3/Callmex). To run it, type
    % /c/cs223/hw3/Tests/test.Callme
    
    Unlike 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.

  2. Keep track of how you spend your time in completing this assignment. Your log file should be of the general form (that below is fictitious):
         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 This log will generally be worth 5-10% of the total grade.

    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".

  3. The submit program can be invoked in eight different ways:
    % /c/cs223/bin/submit  3  Makefile Callme.c hash.c hash.h time.log
    
    submits the named source files as your solution to Homework #3;
    % /c/cs223/bin/check  3
    
    lists the files that you submitted for Homework #2;
     % /c/cs223/bin/unsubmit  3  error.submit bogus.solution
    
    deletes 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  Callme
    
    runs "make" on the files that you submitted previously for Homework #4;
    % /c/cs223/bin/testit  5  Callme
    
    runs 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.log
    
    protects the named files that you submitted previously for Homework #6 (so they cannot be deleted accidentally);
    % /c/cs223/bin/unprotect  7  util.c time.log
    
    unprotects the named files that you submitted previously for Homework #7 (so they can be deleted); and
    % /c/cs223/bin/retrieve  8  common.c time.log
    
    and
    % /c/cs223/bin/retrieve  8  -d"2017/01/21 20:00" util.c
    
    retrieve 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).
  4. 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").

  5. The function exit() allows your program to stop immediately, without having to terminate any surrounding loops or to return to main() from a function. (To use it you must #include the header file <stdlib.h>.)
  6. Callme reads from the command line and a dictionary file and writes to stdout, but does no other input/output.