ASCII character code Counter Solution.ZIP

ASCII character code Counter Solution

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. In the next part you will add features allowing a user to list input files and/or an output fle on the command line.

Complete counts.cpp using the tools provided in common.h as follows:
Read characters from standard input until 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.
Keep a running count of each different character encountered in the input, and keep count of the total number of characters input.

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.

Print a neat table that shows each different input code, the corresponding character and its count, and print the total count at the end. Do not print any rows for ASCII codes that are not included in the input text.

You must exactly match the format of our solution's basic results, and so you must use the symbols and functions defined in common.h. Do NOT print anything any other way.Use prHeader one time at the start.
Use prCountStr for each row that corresponds to a special character (codes 0-32, and 127), and use the symbol strings provided in common.h.
Use prCountChr for each row that corresponds to a printable character (codes 33-126).
Use prTotal one time at the end.

You can test it by typing text manually, in which case you must enter 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.txt

Another 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.
Enhance counts.cpp so that it responds to command line arguments as specified below. Here is an example program showing how command line arguments can be processed: args.cpp.
Let the user enter input filenames and/or an output filename on the command line.

If any input files are requested, then read from those files instead of cin - count all of the characters in all of the input files as one set of input data.
if a command line argument begins with '-o', then the next command line argument is an output filename (-o name). In that case print results to the file instead of cout. Ignore any command line arguments that may follow the output filename.

Signal errors by using the functions defined at the bottom of common.h:
Use badFile if a file (whether input or output) cannot be opened.
Use badOption if an argument begins with '-' but the second character is not 'o'.
Use missing if the '-o' option is not followed by a filename (even if the user types -oname with no space before the name).
Match these enhanced results. Notice the last several runs show error messages and no results.
Powered by