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. 

            Rand() does not come from the system clock: uses a default seed of 0.

 

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:

  • Include an identifier in the program header, representing the file for each file to be used in the program
  • Pascal has the capability to save a file as a file of integers, characters, floats, etc.
  • ALWAYS save as a text, otherwise you can only open it with a Pascal program.\
  • There is a difference between the text file itself and the name of the file itself, one is the object itself, the other is the label of the object [string]
  • Never hardcode a filename into a program, Dr Adams wants to input her own file names.

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—

Troy gets a gold star for knowing Debug -->Output

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:

      • integers in Free Pascal are 16 bit numbers which was the  standard at the time Pascal was released
      • maxint is the maximum integer, for Free Pascal it is 32767
      • add 1 to maxint—wraps to negative -32768
      • multiply maxint by maxint—1.
      • BE CAREFUL

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

 

Troy’s Gold Star Count: