Variables, Parameters

First let's look at a complete bike-and-car program, paying attention to new features such as use of the "common" statement.

The program begins with

I've separated out the plotting routine from the routine calculating the intersection points. First, because they're separate tasks, second, because I wanted an illustration of a "common" block to define global variables. The display_time routine both receives information through the usual passed parameters, and knows about the overall car and bike information through the common statement.

Now the main body, which does the calculation of the intersection times. Notice that with use of an array to store intersection times, I can avoid some of the complexities of the nested if-then-else statements I would otherwise need.

Example call:

And the graphical result:

Now let's look at a shorter example illustrating local and global variables, and how if you pass a variable as an argument to a function or procedure, any changes to the argument will affect the original variable's value.

When run,


Taner Edis
Home
Last modified: January 25, 2007