O'Reilly logo

Practical C++ Programming, 2nd Edition by Steve Oualline

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 27. Putting It All Together

For there isn’t a job on the top of the earth the beggar don’t know, nor do.

Kipling

In this chapter we create a complete program. Every step of the process is covered, from setting forth the requirements to testing the result.

Requirements

Before we start, we need to decide what we are going to do. This is a very important step and is left out of far too many programming cycles.

This chapter’s program must fulfill several requirements. First, it must be long enough to demonstrate modular programming, but at the same time short enough to fit inside a single chapter. Second, it must be complex enough to demonstrate a wide range of C++ features, but simple enough for a novice C++ programmer to understand.

Finally, it must be useful. This is not so simple to define. What’s useful to one person might not be useful to another. We decided to refine this requirement and restate it as “It must be useful to C++ programmers.” The program we have selected reads C++ source files and generates simple statistics on the nesting of parentheses and the ratio of comments to code lines.

The specification for our statistics program is:

Preliminary Specification for a C++ Statistics Gathering Program
Steve Oualline
February 10, 2002

The program stat gathers statistics about C++ source files and prints them. The command line is:

stat files

where files is a list of source files. Example 27-1 shows the output of the program on a short test file.

Example 27-1. stat/stat.out ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required