Sams Teach Yourself C++ in 21 Days

(singke) #1
In the few years since the first edition of this book, programmers have responded to the
demands of users, and, thus, their programs have become larger and more complex. The
need for programming techniques to help manage this complexity has become manifest.
As programming requirements change, both languages and the techniques used for writ-
ing programs evolve to help programmers manage complexity. Although the complete
history is fascinating, this book only focuses briefly on the key part of this evolution: the
transformation from procedural programming to object-oriented programming.

Procedural, Structured, and Object-Oriented Programming ..............................


Until recently, computer programs were thought of as a series of procedures that acted
upon data. A procedure, also called a function or a method, is a set of specific instruc-
tions executed one after the other. The data was quite separate from the procedures, and
the trick in programming was to keep track of which functions called which other func-
tions, and what data was changed. To make sense of this potentially confusing situation,
structured programmingwas created.
The principal idea behind structured programming is the idea of divide and conquer. A
computer program can be thought of as consisting of a set of tasks. Any task that is too
complex to be described simply is broken down into a set of smaller component tasks,
until the tasks are sufficiently small and self-contained enough that they are each easily
understood.
As an example, computing the average salary of every employee of a company is a rather
complex task. You can, however, break it down into the following subtasks:


  1. Count how many employees you have.

  2. Find out what each employee earns.

  3. Total all the salaries.

  4. Divide the total by the number of employees you have.
    Totaling the salaries can be broken down into the following steps:

  5. Get each employee’s record.

  6. Access the salary.

  7. Add the salary to the running total.

  8. Get the next employee’s record.


8 Day 1

Free download pdf