CS3060 (Spring 2013): Programming Assignment 1

C++, I/O


The UNIX utility wc counts the number of lines, words, and characters in a provided file (actually a little bit more than that, as shown by the manual page). This program is implemented in C in the coreutils package on linux (similar implementation on the real UNIXes). In this assignment, we will implement four programs, called fstats, lines, words, and chars, which will all share code from a "common" source file and be built from a single makefile.


  1. Create a total of seven files:
  2. Your Makefile should contain a target called "all" that depends on the targets that build each of the resulting programs, as well as those four targets and four targets for each of the necessary object files.
  3. Write functions called lines, words, and chars in common.h and declare them in common.h. Call the relevant functions from each program's main. Each of these functions should take an istream to count.
  4. Run your programs on http://norvig.com/big.txt and compare your results to those of wc. If you don't get the exact numbers, don't sweat it (there are some very specific quirks of wc), but you should get within 10 or so on all counts.


Submit all source code (the seven files listed above) in as compact a format as possible (I recommend using a2ps with the command line a2ps -2 -C -E -A fill -o output.ps input1 input2 ...) along with the output of your programs (clearly labeled) and of wc (again, clearly labeled). DO NOT use a font size smaller than 8 or larger than 10. DO use a monospaced font. If possible, print line numbers and syntax higlighting (the a2ps command above will do this).