CS 3113: Project 0
Goals
The goals of this project are to:
- Develop your C/Linux programming and compiling skills,
especially related to standard I/O
- Ensure that your class VM is running correctly
- Ensure that your code submission procedures follow our specifications
Proper Academic Conduct
The code solution to this project must be done individually. Do not
copy solutions to this problem from the network and do not look at or
copy solutions from others. However, you may use the net for
inspiration and you may discuss your general approach with others.
Specification
Program Invocation
The command-line interface to your program is as follows:
./project0 [u]
- Your program must accept 0 or 1 arguments. The brackets above
indicate an optional parameter
- If no arguments are specified, then the output will be in
lower case letters
- If there is one argument and it is equal to the string "u"
(exactly), then the output will be in upper case letters
- For any other cases, your program must print an error message
to STDERR and terminate
Program Behavior
Your program will accept lines of input until an end-of-file (EOF) is
reached, at which point it will terminate.
- Each line of input is composed of at most 9 decimal digits (0
... 9), followed by a newline.
- After receiving each line, your program will translate the
digits into the corresponding English text. By default, the
text is lower case, however, if a 'u' is specified as a program
parameter, then the output text must be entirely in upper case.
- Each line of inputs results in one line of output, terminated by a newline character.
Notes:
Examples
Program Invocation
./project0
Input Text
192
18
23400
100001
Output Text
one hundred ninety two
eighteen
twenty three thousand four hundred
one hundred thousand one
Program Invocation
./project0 u
Input Text
123456789
12000018
14000
101
11
1
01
00001
000
Output Text
ONE HUNDRED TWENTY THREE MILLION FOUR HUNDRED FIFTY SIX THOUSAND SEVEN HUNDRED EIGHTY NINE
TWELVE MILLION EIGHTEEN
FOURTEEN THOUSAND
ONE HUNDRED ONE
ELEVEN
ONE
ONE
ONE
[OUTPUT NO TEXT FOR THIS CASE, JUST THE NEWLINE]
Program Invocation
The following example invocations must result in an error message being printed and the program terminating:
./project0 a
./project0 u a
./project0 u a b
Submitting Your Program
- Your submission is composed of the following files, named exactly as shown (including casing):
- project0.c: your source file
- Include your name and project number at the top of the file
- Makefile: the make file that:
- all: compiles your program (this is the default behavior)
- clean: deletes the executable file (project0) and any intermediate files (.o, specifically)
- README.txt: documentation
- Include your name and project number at the top of the file
- Document any Internet resources that you consulted (URLs)
- Document any peer class members that you discussed your solution with. Note that you may not look at or share code that solves this specific problem
- Documentation requirements: function-level and inline
documentation are important components of writing code. They help
you to organize your thoughts while programming and help to
communicate the method and the intent of the code to your future
self or to collaborators (of course, you will not have collaborators
in this class). While we will not be specifically grading
documentation in this class, we will not be able to comment on your
code unless it is sufficiently documented. This will be true whether
you are asking for help before the submission deadline or looking
for feedback on your solution after the deadline. In short, you
should take the time to properly document your code as you develop
it.
- Submit your files:
- Create a zip file named project0.zip containing
your source code, Makefile and README.txt file. The
following Linux shell command will do this for you:
zip project0.zip *.c Makefile README.txt
Note I: this is a good thing to add to your Makefile.
Note II: do not include object files, executables or
temporary files in your zip file.
- Submit your zip file to Gradescope (access via Canvas).
Shortly after your submission, you will receive
automated feedback and a grade for the
correctness component of your grade.
- You may submit multiple times until the deadline.
- To be counted as on time, your solution must be submitted to the Gradescope server by 11:45:00 pm on Tuesday, Sept. 10th. Grade penalties will be imposed for late submissions (see the syllabus for the details).
Grading Criteria
- README.txt (10%): contains the required information
- Makefile (10%): satisfies the make file requirements
- Correctness (80%): passes all of the (hidden) unit tests
Testing
You are responsible for generating your own test cases.
We have provided a couple of samples to get you started, but keep in
mind that we have other tests that are hidden from you.
- Download the following file: project0_public_tests.tar
- Copy the file into your working project directory on your VM
- In a shell on your VM: cd to your project directory and
type:
tar -xvf project0_public_tests.tar
This will unpack this archive file into your local
directory. (do an ls to see what new things have appeared)
- Invoke a test:
./project0 < tests_public_lower/lowercase.txt > output.out
This will start you program and pipe the contents of the
specified file into your program (as if you typed the contents). The
output from your program will be stored in the file output.out
- Compare your program against the reference file:
diff -b -B output.out tests_public_lower/lowercase.txt.out
This compares the contents of these two files. Any differences
will be highlighted on a line-by-line basis. If diff
does not generate any output, then the two files are identical
(the state that you want to be in). Note that the parameters
that we give to diff ignore extra spaces and extra
newlines.
Hints
- Remember that characters use the ASCII encoding. You can take
advantage of this to make your implementation simple.
- For each triple of digits, the code to generate the text is the same, except for the suffix (million, thousand).
- Useful C functions:
- fgets()
Example:
char buf[100];
fgets(buf, 100, stdin);
This call will read at most 100 characters from the STDIN pipe (it stops when 100 characters are read, a newline is found or the end-of-file is reached). fgets() returns buf if something is read and NULL if the end-of-file marker is reached.
- fprintf()
This function behaves like printf(), except you can specify which stream will receive the output (first parameter). stdout and stderr are valid choices here.
- free()
- getline()
- strcat()
- strlen()
- malloc()
- printf()
- toupper()
- You can ask your VM about any of the above functions. For example, type the following into your shell:
man fgets
- Useful libraries (which define the above functions):
- stdio
- ctype
- string
- stdlib
- You can simulate an end-of-file marker (EOF) at the terimal by typing CTRL-d
Addenda
andrewhfagg at gmail.com
Last modified: Tue Sep 10 11:20:53 2019