PA5 can be done either in two-people teams or individually. If you are working with a partner, be sure that both partners' names are in a comment at the top of the source code file, and be sure to properly form a group for this project in the submit.cs system.
We suggest you follow the instructions in sequence. First you are asked to write a program that performs a basic task (namely counting the number of times each ASCII character code occurs in the standard input, and printing results to standard output). You should do Part 1 and test it carefully to make sure it is working before proceeding to the next step. Half credit will be given just for accomplishing this basic part successfully. In the next part you will add features allowing a user to list input files and/or an output fle on the command line. There is a program skeleton and another necessary file this time. Either download counts.cpp and common.h, or get copies as follows from ~cs16/pa5/ and we suggest you store them in a new directory in your own account at CSIL, specifically ~/cs16/pa5. cp ~cs16/pa5/counts.cpp ~/cs16/pa5/ cp ~cs16/pa5/common.h ~/cs16/pa5/ The parameters defined for the main function in counts.cpp should be ignored while you work on Part 1, but leave them in the function header. These parameters are used in Part 2 for processing "command line arguments" (data typed on the command line after a program's name). Our textbook does not cover this topic, but it will be covered in lecture, and there is a demonstration program to look at below. If you want further guidance on this topic, see this nice command line argument tutorial from Prof. Stewart Weiss. Our executable solution is |
EOF
(the end-of-file mark)
is read (see the textbook page 353, and know that cin has most of the same features
as input file streams. Do not prompt the user to enter text - just read data as soon
as the program starts.Note there are a total of 128 ASCII codes, equal to the value of the symbolic constant NUM defined in common.h. Get familiar with the features of common.h - many of them are handy, and you will be required to use some of them in later steps. |
prHeader
one time at the start.prCountStr
for each row that corresponds to a special character
(codes 0-32, and 127), and use the symbol strings provided in common.h.prCountChr
for each row that corresponds to a printable
character (codes 33-126).prTotal
one time at the end.ctrl-D
on Linux (or ctrl-Z
on Windows) to end the input. Or better, test it
by redirecting a file using the Linux redirection operator ('<'
).
For example, to input this sample text file named sample.txt,
in our second sample run, notice that we typed the following:
./counts < sample.txtAnother good input file for testing is allchars.txt which contains one of each ASCII character code. Of course, many of these codes don't show up well when you view it in your web browser, but your program should be able to identify them. Here's the result (of course): allchars-out.txt. A copy of allchars.txt is in ~cs16/pa5/ too.
Make a backup copy of counts.cpp before attempting Part 2. A fully working basic version (i.e., just Part 1) will earn half-credit for this project, more points than a broken enhanced version that we cannot test at all. |
-o name
). In that case
print results to the file instead of cout. Ignore any command line arguments that
may follow the output filename.badFile
if a file (whether input or output) cannot be opened.badOption
if an argument begins with '-'
but the second character is not 'o'
.missing
if the '-o'
option is not followed by a filename
(even if the user types -oname
with no space before the name).~submit/submit -p 962 counts.cppBe sure to wait for the test results. If you score 100/100 and you've followed all of the other rules, then you'll earn full credit.
Do not alter counts.cpp in response to these challenges - work with a copy instead.
-z
' that is a signal to print zero counts -
that is, the table will include a row for every ASCII code.-s
' that signals the user wants the output to be printed
in sorted order, greatest count first and smallest count last. Be careful when sorting
the counts to maintain their correspondence with the letters counted.-a
, for example could mean to just print alphabetical characters,
-d
could mean just digits (0-9), -p
could be just punctuation, and so on.
Decide how to handle combinations of these options too.-t
.