Jan 23, 2008
Assignment #2: ADT
Inspiration credit to Joe Zachary, University of Utah (random writer).
Due Wed Jan 30th 2:15pm
You've been introduced to the handy CS106 class library, now it's time to put these objects to work!
In the role of client with the low-level details abstracted away, you can put your energy toward
solving more interesting problems. Your next assignment is to write two short client programs that
heavily leverage our classes to do nifty things. The tasks may sound a little daunting at first, but
given the power tools in your arsenal, each requires only a page or two of code. Let's hear it for
The assignment has several purposes:
1. To more fully experience the joy of using pre-written classes. Most of the heavy-lifting is
handled by objects from our class library.
2. To stress the notion of abstraction as a mechanism for managing data and providing
functionality without revealing the representational details.
3. To become familiar with using C++ class templates.
4. To gain practice with classic data structures such as the stack, queue, vector, map, and set.
Part A— Random writing and Markov models of language
In the past few decades, computers have revolutionized student life. In addition to providing no end
of entertainment and distractions, computers also have also facilitated much productive student
work. However, one important area of student labor that has been painfully neglected is the task of
filling up space in papers, Ph.D. dissertations, grant proposals, and recommendation letters with
important sounding and somewhat sensible random sequences. Come on, you know the
overworked TA/professor/reviewer doesn't have time to read too closely…
To address this burning need, the random writer is designed to produce somewhat sensible output
by generalizing from patterns found in the input text. When you're coming up short on that 10-page
paper due tomorrow, feed in the eight pages you already have written into the random writer, and
voila! another couple of pages appear. You can even feed your own .cpp files back into your
program and have it build a new random program on demand.
How does this work?
Random writing is based on an idea advanced by Claude Shannon in 1948 and subsequently
popularized by A.K. Dewdney in his Scientific American column in 1989. Shannon's famous paper
introduces the idea of a Markov model for English text. A
is a statistical model that
describes the future state of a system based on the current state and the conditional probabilities of
the possible transitions. Markov models have a wide variety of uses, including recognition systems
for handwriting and speech, machine learning, bioinformatics, even Google's PageRank algorithm
has a Markov component to it. In the case of English text, the Markov model is used to describe the
possibility of a particular character appearing given the sequence of characters seen so far. The