Class Crib Notes for CPSC 110                                Brent Dingle

                                    Friday, March 22, 2002

 

Reminders:

Lab 5 due Monday and Tuesday.

Quiz next Wednesday.

READ the book – Chapter 5.

 

Last time:

Last time we discussed functions. Functions are very similar to procedures.

Recall what the words local, global, block, scope and associated words mean.

 

We are now going into Chapter 8.

 

After you have been programming for some time you will discover that you often create the same functions over and over again. This has led to the development of libraries – collections of functions that people have already created and can use in later programs.

 

For example the clrscr function is in the library CRT.

 

Pascal calls these COMPILED libraries UNITS.

 

While there are some units already made for you to use, eventually you may want to create your own. To do this you must know how to write the source code to do it.

 

The structure of the source code for a UNIT is as follows:

 

UNIT [name];

 

INTERFACE

     { USES declarations go here }

     { CONST, TYPE and VAR declarations go here }

     { Procedure and Function declarations go here }

 

IMPLEMENTATION

    { private CONST, TYPE and VAR declarations go here }

    { Place Procedure and Function bodies here }

 

BEGIN   { this begin is optional and only needed if you have initialization stmts below }

    { Initialization statements go here }

END. { the end required, regardless of what is placed above this }

 

Anything listed in the INTERFACE section is PUBLIC – these are the things you will want other programs to use. However the DETAILS are NOT made PUBLIC. So we just have names and types.

 

Anything listed in the IMPLEMENTATION section is PRIVATE – these are the things that the other programs do NOT want to or need to know. You put all the DETAILS in this section.

 

You also may initialize stuff after the implementation section. For example if for some unknown reason you always wanted a variable named PI to be available you would declare it in the interface section and initialize it to 3.1415 between the begin and end after the implementation section.

 

 

 

 

 

What you MUST remember: 

 

PROGRAM la;
USES CRT;
VAR
    lambert : string;
BEGIN
    clrscr;
    lalalalalalalala ….
END.

 

 

To better understand: 

The unit BooleIn described on page 282 and 283 along with the corresponding program TestBooleIn might be a good place to start.

 

Your TA’s should be able to demonstrate how to create and use you own units.