Notes 430 Section 2
September 28th 2006
Problem 2—
In FORTRAN, all parameters are passed by reference, so functions should only return one thing-- never change the value of their parameters. If you need to change two values, use a subroutine.
Always save notes from Blackboard telling you that you have had a successful submit to the Digital Dropbox in case something goes wrong.
Division by 0 is a runtime error
FORTRAN’s included functions:
(looked at and supplemented first section’s notes)
URLS:
http://www.ncl.ucar.edu/Document/Functions/Built-in/index.shtml
http://www.personal.psu.edu/faculty/j/h/jhm/f90/lectures/7.html
PASCAL NOTES:
Files:
Playing with TestFiles.pp
assign(infile, infileName) links the internal and the external file names
Internal name presents an address and the file name is a string.
reset(infile) moves the read head to the beginning of the input file
rewrite(outfile) moves the write head to the beginning of the output file---cannot retrieve what was in the file before the rewrite
always close your files—do not rely on the compiler to do it for you.
Compile-Make-Build-Run--Step Over, line by line, goes between code and DOS prompt.
Putting in a bad filename does not cause an error until reset.
Exit
code 2 at line 21—
Playing with testFiles2.pp
When you pass in outfile or output as a parameter, you are passing addresses- must be var parameters.
writeln(outfile, “this goes to the file”);
Be sure to check out the Pascal Tutorial!
Must declare in the order: const, type, var
Identifier Rules: Reserved words:
and array begin case const div
do downto else end file for forward function goto if in label mod nil not of or packed procedure
program record repeat set then to type until var
while with
Data Types:
Standard Functions: http://www.taoyue.com/tutorials/pascal/pas1f.html
Trig functions are in radians
Ordinal Data Types: have a predefined order, such as integers or chars
Formatting output: value : field_width : decimal_field_width (equiv to F3.2)
eoln(file_variable) --boolean
eof(file_variable)
EOF from keyboard—ctrl-Z
Booleans: <> is not-equal
Do not need a semicolon before an end, but do not put one before an else
CASE: looked at last class—otherwise (optional) for cases not specified, no colon
LOOPS:
FOR, counted loop, checks first, increments in steps of 1
for index
:= StartingLow to EndingHigh do
statement;
can use any ordinal
variable
but to decrement:
for index
:= StartingHigh downto
EndingLow do
statement;
never put a semi-colon directly following a do
REPEAT…UNTIL: post test loop
SUBRANGES:
type
DaysOfWeek = (Sunday, Monday,
Tuesday, Wednesday,
Thursday, Friday, Saturday);
DaysOfWorkWeek = Monday..Friday;
SUBPROGRAMS:
Procedures:
Have a semicolon at the end, not a period. Must go at the top of the file
Call using just the name
Parameters: by default value parameters, actual and formal seperate
Var parameters are pass by reference, FILES MUST be VAR
procedure Name (a, b : integer; VAR c, d : integer);
when changed in the procedure, they affect the calling parameters.
FUNCTIONS: function Name (parameter_list) : return_type;
Putting a function on the right causes recursion—do not forget your termination case
ARRAYS:
Homogeneous,
type
typename
= array [enumerated_type] of another_data_type;
Multidimensional: row major order
type
datatype
= array [enum_type1, enum_type2] of datatype;
RECORDS: heterogeneous data types
TYPE
TypeName
= record
identifierlist1 : datatype1;
...
identifierlistn : datatypen;
end;
POINTERS: next time
Look out for a PASCAL programming assignment for the weekend
![]()
![]()
![]()