January 18, 2008
CS106 Library Classes
Kudos to Julie Zelenski for this fantastic summary of the CS106 utility and container classes.
This winter I’m going to try something that another lecturer successfully tried last
After we cover the basics of class interface design, publicity versus privacy,
constructors, destructors, and the mechanics of implementation, we’re going to put on
our client caps and learn some of the utility classes written specifically for the CS106
In the past, we’ve focused on both the design and the implementation of each
class, one at a time, alternating between user and implementer.
This time, we’re going to
learn all the classes up front, internalizing their interface, their behavior, their runtime
characteristics, and the situations where they come in most handy.
The ideas modeled
by these classes are common enough that all modern programming languages provided
similar library classes—Java provides things like
, whereas the C++ STL provides classes like
principle, were could just learn the STL classes, but they’re cumbersome and difficult to
use for someone programming in C++ for the very first time.
So we instead go with
some simpler versions of the very same ideas.
This way we can emphasize concept
instead of syntax.
Unfortunately, the reader hasn’t been updated to reflect our new stance on teaching
these classes, so you’ll have to rely on this handout, the reader’s appendix, and Jerry’s
brilliant explanations for a few days until we start talking about implementation.
class provides functionality for dividing a string into separate words or
A scanner comes in quite handy when doing any sort of string or file processing.
Here's a few ideas to get you thinking about its uses:
breaking apart a command entered at the console (e.g. "
find price < 5
dividing a document into component words for textual analysis, such as a word
frequency count, preparing an index, or building a concordance
separating a file pathname into its components (e.g. the sub-directories
evaluating an arithmetic expression, such as
3 + 4 * 7