CS-701 Assignment 2

Introduction

This is an exercise in "coding to specifications." Following the [ Coding Guidelines for this Course ], you are to write a C++ program which exactly mimics the Unix wc command.

Requirements

Read the man page for the wc command, and experiment with it to make sure you understand what the program does. Then, write a single source module named wc.cc which performs exactly the same operations as the wc command.

Command Line Options

Use the getopt_long() function to process the following command line options:

Option Interpretation
-c or --chars Print the number of characters only.
-l or --lines Print the number of lines only.
-w or --words Print the number of words only.
-L or --max-line-length Print the length of the longest line only.
-? or --help Print a "usage" message and exit.

Options may be combined, so that "-c -w" (or -cw) will print the counts for both the number of characters and the number of words.

Until we have our Linux virtual machines, you will have to use Forbin, which does not support the getopt_long() function. So if you start working on forbin, ignore the long versions of the options and process only the short versions (-c, -l, -w, and -L) using the getopt() function. You can add the code for the long options later.

Other Requirements

Testing

Test your program to be sure it handles all combinations of options and any number of input file names (including zero). Except for error messages for files that can't be read, your progam's output should be exactly the same as the output of the system's wc command. You should use the diff command to check for this. For example, one of your tests might be run as follows:
    ./wc -lw file1 file2 file3 > out1
    /usr/bin/wc -lw file1 file2 file3 > out2
    diff out1 out2
(The above diff command should produce no output.)

Due Date and Project Submission

This assignment is due by midnight February 26, 2002.

Follow the instructions in the Coding Guidelines web page for creating a tar file of your "clean" project directory. For this assignment, you will not be using make or rcs for project management, so your tar file should contain just the following: your project directory, which is to contain only the file named wc.cc and an empty subdirectory named RCS. There must be no other files in the tar file.

When your assignment has been coded and tested on your linux virtual machine, send me an email message with the subject line, "701: Assignment 2". Put your name and id number in the body of the message, and include your tar file as an attachment. Send the assignment to me from your linux virtual machine, using the pine email program to send it. (Attach a file by typing Control-J while the cursor is in the heading part of your message.)

Submit the assignment to me using my account (vickery) on the linux virtual machine.