Some advice before we start: C++ (like C) has a lot of concepts in it that work almost identically to those found in Java. If you view C++ code as somewhat deranged Java, you should be able to read a lot of it before having to consult the reference manual.
Put all of your files for this homework in a directory named 'hw5'. Run
the command 'turnin -ccse490c hw5
'. Run turnin on the
directory itself - don't run 'tar' on this directory before turnin.
Make sure your code works with the compiler on attu (g++) before your turn it in!
For this assignment, you will create a word count class, then subclass it to be
more detailed. You'll also use rcs
to keep track of changes, as
you make them.
WordCounter
, and has the following public functions:
virtual int getLines(); virtual int getWords(); virtual int getChars(); virtual void processChar(char c); virtual void printResults();
A WordCounter
object should start off with getLines(), getWords()
and getChars() returning 0. processChar() will be repeatedly called, and the
appropriate line, character and word counts should be updated. printResults
should print the line, word and character information to the screen.
WordCounter should exhibit behavior identical to that found with wc
, except perhaps for minor whitespace issues.
How will you know your implementation works? You'll also create a main() function that tests it, of course.
WordCounter
working, create an RCS repository
for it before you continue working on it (which will break it, at least
temporarily). man rcsintro
will provide more information about
most of what is going on here. (It's short...)
// $Header$
ci XXX
for each .cpp and .h file, and your Makefile (putting the filename in place of
XXX).
rcs -nStep1: RCS/*
co XXX
to obtain a (read-only) copy of XXX.
co -l XXX
to get one (and also to "lock" the file in the repository so no one else can
get a writable copy until you do a ci
, including you!).
Create a class named FreqCounter
that is a subclass of
your implementation of WordCounter
from Step 1. FreqCounter
has the following (additional) functions:
virtual int getCharCount(char c); virtual double getCharFreq(char c);
getCharCount() should return the total number of occurrences seen so far for
the character c.
getCharFrequency() should return the fraction of the total number of characters
the given character represents. (In both cases, a "character" is anything
passed in, not just, say, alphanumerics.)
You should also override printResults() to output the additional information now collected.
Update your test program (main()) to test the new funcationality.
main.cpp,
WordCounter.h, WordCounter.cpp, FreqCounter.h, FreqCounter.cpp, Makefile
,
plus the RCS repository and possibly a script and data files for testing
purposes.