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.
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 ...
Get Practical C++ Programming, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.