Definitions

An algorithm is a set of precisely defined steps to calculate an answer to a problem or set of problems, and which is guaranteed to arrive at such an answer eventually. As this implies, a set of steps that might never end is not, strictly speaking, an algorithm.[3]

[3] I should note that there is some disagreement on this fine point of definition. Some people consider a procedure to be an algorithm even if it may never end.

Programming is the art and science of solving problems by the following procedure:[4]

[4] This definition is possibly somewhat misleading since it implies that the development of a program is straightforward and linear, with no revisions required. This is known as the “waterfall model” of programming, since water going over a waterfall follows a preordained course in one direction. However, real-life programming doesn't usually work this way; rather, most programs are written in an incremental process as assumptions are changed and errors are found and corrected, as we'll see in Chapters 11 and 12.

1.
Find or invent a general solution to a class of problems.

2.
Express this solution as an algorithm or set of algorithms.

3.
Translate the algorithm(s) into terms so simple that a stupid machine like a computer can follow them to calculate the specific answer for any specific problem in the class.

At this point, let's see what Susan had to say about the above definition and my response to her.

Susan: Very descriptive. How about this definition: Programming is the process of being creative using the tools of science such as incremental problem solving to make a stupid computer do what you want it to. That I understand!

Your definition is just fine. A definition has to be concise and descriptive, and that you have done — and covered all the bases. But you know what is lacking? An example of what it looks like. Maybe just a little statement that really looks bizarre to me, and then say that by the end of the chapter you, the reader, will actually know what this stuff really means! Sort of like a coming attraction type of thing.

Steve: I understand the idea of trying to draw the reader into the “game”. However, I think that presenting a bunch of apparent gibberish with no warning could frighten readers as easily as it might intrigue them. I think it's better to delay showing examples until they have some background.

Now let's return to our list of definitions:

Hardware refers to the physical components of a computer, the ones you can touch. Examples include the keyboard, the monitor, the printer.

Software refers to the nonphysical components of a computer, the ones you cannot touch. If you can install it on your hard disk, it's software. Examples include a spreadsheet, a word processor, a database program.

Source code is a program in a form suitable for reading and writing by a human being.

An executable program (or an executable, for short) is a program in a form suitable for running on a computer.

Object code is a portion of a program in a form suitable for incorporation into an executable program.

Compilation is the process of translating source code into object code. Almost all of the software on your computer was created by this process.

A compiler is a program that performs compilation as defined above.

How to Write a Program

Now you have a definition of programming. Unfortunately, however, this doesn't tell you how to write a program. The process of solving a problem by programming in C++ follows these steps:

1.
Problem: After discussions between the user and the programmer, the programmer defines the problem precisely.

2.
Algorithms: The programmer finds and/or creates algorithms that will solve the problem.

3.
C++: The programmer implements these algorithms as source code in C++.

4.
Executable: The programmer runs the C++ compiler, which must already be present on the programmer's machine, to translate the source code into an executable program.

5.
Hardware: The user runs the resulting executable program on a computer.

These steps advance from the most abstract to the most concrete, which is perfectly appropriate for an experienced C++ programmer. However, if you're using this book to learn how to program in C++, obviously you're not an experienced C++ programmer, so before you can follow this path to solving a problem you're going to need a fairly thorough grounding in all of these steps.

This description is actually a bit oversimplified, as we'll see in the discussion of linking in Chapter 5, “Functional Literacy”. For now, let's see what Susan thinks about this issue.

Susan: With all the new concepts and all the new language and terms, it is so hard to know what one thing has to do with the other and where things are supposed to fit into the big picture. Anyway, you have to understand; for someone like me, this is an enormous amount of new material to be introduced to all at once. When you are bombarded with so many new terms and so many abstract concepts, it is a little hard to sort out what is what. Will you have guidelines for each of the steps? Since I know a little about this already, the more I look at the steps, I just know that what is coming is going to be a big deal. For example, take step 1; you have to give the ingredients for properly defining a problem. If something is left out, then everything that follows won't work.

Steve: I hope you won't find it that frustrating, because I explain all of the steps carefully as I do them. Of course, it's possible that I haven't been careful enough, but in that case you can let me know and I'll explain it further.

Unfortunately, it's not possible for me to provide a thorough guide to all of those steps, as that would be a series of books in itself. However, there's a wonderful small book called How to Solve It, by G. Polya, that you should be able to get at your local library. It was written to help students solve geometry problems, but the techniques are applicable in areas other than geometry. I'm going to recommend that readers of my book read it if they have any trouble with general problem solving.

The steps for solving a problem via programming might sound reasonable in the abstract, but that doesn't mean that you can follow them easily without practice. Assuming that you already have a pretty good idea of what the problem is that you're trying to solve, the algorithms step is likely to be the biggest stumbling block. Therefore, it might be very helpful to go into that step in a bit more detail.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset