Algorithmic Thinking

The first step in programming is to determine the algorithm. An algorithm is a method for solving a problem. Always plan your programs on paper first. You will _save_ time this way!

"Top-down design" is dividing big problems into smaller problems that can be solved individually. Solving these smaller problems individually is called "stepwise refinement."

In planning your program, you need to think about what steps need to be performed and what data you will need. You need to think about grouping together statements into functions that perform discrete tasks. Whenever possible, try to create general purpose functions that can be re-used in other programs.

Example:

We need to program a robot to feed the cat. What steps do we need:

So, how might we group these into functions?

We might create a general purpose function for getting things. We will supply this function with what we want and where to find it. Then this same function can be used to get us some ice cream!

We might create a general purpose can opening function so that it can open any can we tell it to open. That way we can have the robot open a can of peaches to go with our ice cream!

We might create a general purpose function for spooning food into a dish. This will also be useful for serving ice cream.

And finally, we might create a general purpose serving function so that the dish is served to whomever we wish.

We must be very careful in planning our robot program. Otherwise, we will get the cat food and the cat will get the ice cream!


Other Notes:

KB=1024
MB=1024 x 1024 (about a million)
GB=1024 x 1024 x 1024 (about a billion)
TB=1024 x 1024 x 1024 x 1024 (about a trillion!)

cin stands for "common input" (some texts say "console input")
cout stands for "common output (some texts say "console output")