Chapter1 - Chapter 1 - Basic Programming Concepts The...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Ch1 - 1 Chapter 1 - Basic Programming Concepts The diagram below illustrates the essence of computer programming. The computer is a mindless robot which simply follows the instructions given to it. It follows these instructions very quickly, and very accurately, but that’s all it does. It doesn’t think. All the thinking is done by the programmer. He (or she) considers the problem to be solved, devises a suitable set of instructions (an algorithm ), and gives these instructions into the computer. The computer then follows (executes) the instructions, and, if they are correct, the desired solution is achieved. Thinks about problem, adds inspiration, and produces instructions. Mindlessly follows instructions. Programmer Computer Problem m Instructions Solution It is important to keep in mind that computers are dumb (dumber than even your average professor). While they may sometimes look very intelligent indeed (e.g. “Deep Blue” – IBM’s famous chess playing computer), this is just because they are following a very clever set of instructions. Computers simply do what they are told to do. If they are given silly instructions, they will produce silly results. Hence the saying: “garbage in – garbage out”. The basics concepts can be illustrated with examples from everyday life. Imagine, for example, that we are hungry (a definite problem). We think about the issue, decide that we would like some muffins, and come up with a suitable recipe (a set of instructions). The recipe is given to a cook who mindlessly follows it and (presuming that the recipe is any good) we wind up with a delicious batch of muffins (a solution to our problem). As can readily be seen by comparing the diagram below to the diagram above, the entire process is analogous to computer programming. The only key difference is that we have “programmed” a cook rather than a computer. Thinks about problem, adds inspiration, and produces instructions. Mindlessly follows instructions. Us Cook Hunger (problem) Recipe (instructions) Muffins (solution)
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Ch1 - 2 Our recipe might be: - Obtain 2 cups flour, 3 teaspoons baking powder, 1 teaspoon salt, 2 tablespoons sugar, 2 eggs, 1 cup milk, and ¼ cup melted butter. - Beat the eggs well. - Stir the flour, baking powder, salt, and sugar together. - Combine beaten eggs, milk and melted butter, and then add all-at-once to the dry ingredients. - Stir quickly until ingredients are just mixed and batter is lumpy. - Fill greased muffin pans 2/3 full and bake at 400 ˚ F for 20 minutes. “Garbage in – garbage out” certainly applies. Suppose that, due to a small typographical error, the recipe given to the cook called for the muffins to be baked at 400 ˚ F for 200 minutes. The results would not be what we expected and would certainly not be much of a solution to our problem. Arguably most real cooks would spot such an outrageous mistake but in order to preserve the analogy between this example and computer programming it must be assumed that the cook does not think at all, but instead
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 19

Chapter1 - Chapter 1 - Basic Programming Concepts The...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online