FORTRAN’s included
functions
srand (integer) is a
subroutine call – it’s not a function
provides a seed – higher is better than
lower – and higher primes are even better as seeds
URLs for FORTRAN functions from Alan and Kurt
Pascal
Code for handling files discussed in class
PASCAL NOTES
Pascal parameter types:
· VAR
o Pass by address
· VALUE
o Pass by copy
o The default
Look at the Pascal Tutorial on the website. It explains everything you need to know to program in Pascal. The structure of a Pascal program is absolute. You must declare variables in the proper order.
Never use a semicolon after the word DO or before the word ELSE.
You can format your output, play with it.
NEVER HARDCODE A FILE NAME IN TO YOUR PROGRAM.
There are four logical operators.
Never test to see if something is EQUAL to true.
There are two branching or selection statements. Behaves like Java in that if there is a single statement then you do not have to create a group. If there is more than one statement you must create a group.
In Pascal, the semicolon is a separator, so you don’t want to put one before an else. You can put one before an end.
In Free Pascal, when you make a new file do not use the template.
TestFiles example code
Provides an overview of file handling.
In testFiles, you will always have output and input (output to the screen, input from the input files). The other two parameters are the file names for the input and output.
Free Pascal will color code syntax for you, so it may be better to use than notepad.
The way you relate an internal name to an external name is with an assign statement. Ex: Assign (inFile, inFileName)
Reset moves the read head to the start of the file.
Rewrite moves the write head to the start of the file. It will destroy what is in a file if anything already exists.
Make sure you close your files when you are done.
You can compile, make or build then run. We will not be building.
testFiles2 example code
The first white line is a plain write statement. It will write directly to the screen.
The second write statement should write directly to the output file.
Every time you want something to go to the screen and the output file, you need to write a write statement for each. You can write a procedure that will take the information to be written and the file name as parameters and have two write statements within the procedure.
NOTE: The file parameter must be a VAR parameter.
Pressing F8 will walk you through the code one line at a time, it will bring up the window when you need to input something.
Homework
Program due on Tuesday.