The old C language provides the program with two types of function parameters: “call by value” and
“array.” (Pointers are used to get around the limitations of “call by value.”)
C++ provides you with lots of new parameter and return types. These include constant and reference
parameters and return values.
Next there is a quick overview of structure programming (top-down programming) and bottom-up
programming. One thing to emphasize is that there have been a lot of different programming
methodologies introduced over the years. Each has its own band of fanatics who support it above all
others. Each has proved that although it is useful, it is not the ultimate programming system.
The current design fad is called “Object Oriented Design.” We get into this later when we get into
classes. “Object Oriented Design” is not the ultimate programming system. This too will pass.
Ideally, what you should teach your students is that there are a lot of programming techniques out there
and the programmer should pick the one that allows him to best organize his program. Don’t blindly
follow the rules if there is some way to make your program clearer and easier to maintain.
Finally, we introduce the tricky subject of recursion. The idea of calling a function from within itself is
foreign to some people. But I’ve programmed in LISP using no looping statements, and you’d be
Page 27
amazed at what you can do recursively when you’re forced to.
Recursion is very simple actually. You just need to remember the two rules:
1. It must have an ending point.
2. It must make the problem simpler.
Live Demonstration
Slide 3 scope/scope.cpp
Slide 6 perm/perm.cpp
Slide 25 length/length.cpp
Classroom Presentation Suggestions
Use the debugger to step through the program on Slide 3 and set watch points for the variables global,
local, and very_local. If you do this right, you will start out with our “watch” window looking
like:
global 0
local <variable out of scope>
very_local <variable out of scope>
(Some debuggers don’t allow you to insert a watch for a variable that is not currently active. In this case
you need to single-step to the middle of the program, set watches on all the variables and restart. This
will prepare your program for the students.)
Step through the program on Slide 6. Emphasize the fact that the statement
int temporary = 1;
constructs and initializes the variable. This will come in handy when classes are discussed. Also, the
variable is destroyed at the end of the block. Using the words “construction” and “destruction” will help
relate this material to the class constructor and destructor member functions.
Practical C++ Programming by manish baranwal
Start from the beginning
