Due 2:00 AM, Friday, 27 January 2017
A previous version of this assignment was based on the following. The pianist and comedian, Victor Borge, proposed an inflationary language, in which numbers and their homophones in words would be incremented by one.
See https://www.youtube.com/watch?v=bcGA4alhPas
For example, "Anyone for tennis?" becomes "Anytwo five elevennis?"
Here are some examples of Total in action.
% echo 23 -20 | ./Total Total: 3 % echo 023 -020 | ./Total Total: 3 % echo 023 020 | ./Total Total: 35 % echo 0X1A -0xa | ./Total Total: 16 % echo 0B101 077 | ./Total Total: 68The staff solution includes a debug option which prints out intermediate results. The debug option is, well, optional. You will not be tested on it.
% cat t1 -9 "4 56" 011 0b11 0x11 "3 \" 4" 5 % ./Total -debug < t1 n: -9 total: -9 n: 9 total: 0 n: 3 total: 3 n: 17 total: 20 n: 5 total: 25 Total: 25 % cat t2 ---9 0\ b11 0b\ 11 0\ xff 0x\ ff 0\ 77 -\ x % ./Total -debug < t2 n: -9 total: -9 n: 3 total: -6 n: 3 total: -3 n: 255 total: 252 n: 255 total: 507 n: 63 total: 570 Total: 570Finally, note that you can pipe the output from another program into Total.
% echo sbs5 cs223ta | ./Total Total: 228 % ll total 40 -rw-r--r-- 1 sbs5 cs223ta 5582 Jan 3 11:00 Makefile -rw-rw-r-- 1 sbs5 cs223ta 35 Jan 3 12:21 t1 -rw-rw-r-- 1 sbs5 cs223ta 44 Jan 3 11:56 t2 -rwxrwxr-x 1 sbs5 cs223ta 9040 Jan 3 12:10 Total -rw-rw-r-- 1 sbs5 cs223ta 2508 Jan 3 12:10 Total.c -rw-rw-r-- 1 sbs5 cs223ta 4152 Jan 3 12:10 Total.o % ll | ./Total Total: 22973
// MAX_LONG: 9223372036854775807which is nearly 20 decimal digits. Note that octal or binary numbers could have more digits. The negative limit is similar. You do not have to handle arithmetic overflows or underflows.
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/hw1/Tests/test.Total(here % is the shell prompt). The script uses make to create Total. To run each test it redirects the test file (e.g., /c/cs223/hw1/Tests/t01.c for Test #01) to the standard input of Total and redirects the standard output to a temporary file. Then it compares this file with the expected output for that input (e.g., /c/cs223/hw1/Tests/t01.cs for Test #01). Your program passes the test only if the two files are identical.
To run your program on the file for Test #01, type
% ./Total < /c/cs223/hw1/Tests/t01.cTo compare the output from your program with the expected output, type
% ./Total < /c/cs223/hw1/Tests/t01.c | cmp - /c/cs223/hw1/Tests/t01.cs(cmp outputs the first character where the files differ) or
% ./Total < /c/cs223/hw1/Tests/t01.c | diff - /c/cs223/hw1/Tests/t01.cs(diff outputs the lines where they differ but uses a looser definition for "identical") or
% /c/cs223/hw1/Tests/test.Total 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. To make all characters visible (except blanks), type
% ./Total < /c/cs223/hw1/Tests/t01.c | cat -vetor
% ./Total < /c/cs223/hw1/Tests/t01.c | od -bc
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 1 Makefile Total.c time.logsubmits the named source files as your solution to Homework #1;
% /c/cs223/bin/check 2lists 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 Totalruns "make" on the files that you submitted previously for Homework #4;
% /c/cs223/bin/testit 5 Totalruns the public test script for Total using the files that you submitted previously for Homework #5; This may not be working. Use the testing instructions given above.
% /c/cs223/bin/protect 6 Total.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 1 Total") after you have submitted the final version of your source files. Better yet, run testit ("testit 1 Total").
Total is easier to write if you can peek at the next character in the standard input without reading it. The macro
#define ungetchar(c) ungetc(c,stdin) // Unread char read from stdinallows you to push a character back onto the standard input. That is, the character C "unread" will be the next character returned by getchar(). The value returned by ungetchar() is its argument, or EOF if the operation was unsuccessful. Note: Every ungetchar() must be preceded by a getchar(), and you can only do one ungetchar() between successive getchar()'s.
You may find this macro useful in writing Total since it allows you to read the next character and then decide that you should not have.
Example:
while ((c = getchar()) != EOF) { if (c == 'C') { c = getchar(); if (c == 'S') printf ("I found a CS in the standard input!\n"); else ungetchar(c); } }