Baby Steps

If we already understand the problem we're going to solve, the next step is to figure out a plan of attack which we will then break down into steps small enough that they can be expressed in C++. This is called stepwise refinement, since we start out with a “coarse” solution and refine it until the steps are within the capability of the C++ language. For a complex problem, this may take several intermediate steps; but let's start out with a simple example. Say that we want to know how much older one person is than another. We might start with the following general outline:

  1. Get two ages to be compared.

  2. Calculate difference of ages.

  3. Display the result.

This in turn can be broken down further, as follows:

  1. Get two ages to be compared.

    1. Ask ...

Get C++: A Dialog Programming with the C++ Standard Library 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.