CS 430 – Section 2

 

Homework assignment clarification:

 

a)      use only ONE  two-dimensional array

b)      printing out the averages of rows before printing the columns is fine

c)      Alternatives for passing in variables into a subroutine (when calculating averages for rows/columns):

a.      Whole array – best choice, since in FORTRAN variables are passed by reference (still efficient).

b.      Row at a time

c.       Column at a time

 

d)      When filling in the random numbers into the array, the columns will be filled in the fastest. because the data is to go in row by row

e)      You can use RAND() (don’t worry that RAND() produces a warning at compile time in Force 2) for the random numbers or find one on the internet and implement your own random number generator.

Use 2 decimal places for outputting averages.

f)        CHANGE TO THE CURRENT ASSIGNMENT:
ZIP together your source code and sample output before posting on Blackboard in the Digital Dropbox

g)      In order to have strings being split on 2 lines use the following:

       | WRITE (6, 20)

20   | FORMAT (1X, ‘This is a really long string asdf asdkfejfs sdoiajekf”,   

    6 | ‘ and the rest of the line ‘)

            h) Built in function in FORTRAN

                        1) MOD (numerator, denominator) – returns the remainder when numerator is divided by denominator takes real or integer arguments

 

                        3) ABS (number) – the number can be REAL or INTEGER, returns the absolute value of the number

                        4) MAX (num1, num2) – finds the maximum value in a ______

                        5) IFIX (REALnumber) – returns a

                        6) SQRT (integer) – finds the square root – returns a ____

                        7) LOG (anyTypeNumber) – returns the natural log of x

                        8) RAND() – returns a random value between 0 and 1 depending on the time clock

                        9) COS (realNumber) – returns the cosine as a realNumber – the parameter is in radians

10) SIN (realNumber) – returns the sine as a realNumber – the parameter is in radians

11) TAN (realNumber) – returns the tangent as a realNumber – the parameter is in radians

                        12) SIND(realNumberOfDegrees) – returns an integer which is the truncated real

                        13) FLOOR (realNumber) – returns as integer which is the truncated real

                        14) MIN(listOfNumbers) – fins the minimum value in a list of homogeneous type numbers

                        15) ATAN (realNumber) – returns the inverse of tangent -- returns value in radians

                        16) CEILING(realNumber) – returns an integer

                        17) SRAND(integerNumber) – sets the seed for the RAND() function

                        18) EXP (realNumber) – returns e to the real number power

                        19) ASIN (realNumber) – returns the inverse of sine -- returns value in radians

 

HOMEWORK (for 09/28/06):

Go home and test the built in function, see if it returns the same thing that we wrote up above.  Write good comments explaining what happens when using the functions.

            NOTE:

Turns out FORTRAN IV only has about 16 built-in functions; some of the functions may have been added to support other FORTRAN languages.

 

 

Pascal Notes

 

Anything mentioned about a programming language in class applies to certain situations. 

Ex.  The following looks different to us, but certain compilers only look at the first 8 characters

        so to the compiler the variables are identical:

            NAMEANDADDRESS1

            NAMEANDADDRESS2

 

            READ (X) is continuous reading (ex read, read, read, read, read…etc)

            READ (LN) only reads until the end of line

- input is a standard input device -- ie. READ (varname)

 

WRITE (X) is continuous output (ex output, output, output, output..etc)

WRITELN (LN) only outputs until the end of line

- output is a standard output device

 

            In a ‘FOR’ loop:          

                        NEVER put a semicolon after a ‘DO’ – this creates an infinite loop

           

            WHILE statement is a ‘pre-test’ loop, if the condition is not met, then

 

            REPEAT … UNTIL – is a post-test loop

           

            MUST have ( ) around conditions in the ‘IF’ statements

 

 

 

Example Pascal programs:

 

program test(input, output);

 

            var num1, num2 : integer;

            type AnimalType = (cat, frog, dog, monkey, pig, horse, tiger);

            var myFavoriteAnimal : AnimalType;    

 

begin

            myFavoriteAnimal := dog;

 

            num1 := 5;

            num2 := 6;

 

            case myFavoriteAnimal OF

                        cat : writeln ('cat is your favorite');

                        dog..monkey : writeln ('dog or monkey');

                        pig, horse, tiger : writeln ('pig, horse, tiger');

            END;

 

            if (num1 < num2) then

                        writeln (num1, ' is smaller than ', num2)

            end.

end.

 

 

Another example by Mike Lam:

 

(* test2.pas - second pascal program *)

 

program test (input, output);

            var num1 : integer;

            type hardware = (mouse, keyboard, monitor, cpu, card);

            var thing : hardware;

            (* CAUSES ERROR  type rodent = (rat, mouse); *)

begin

    num1 := 1;

   

    thing := keyboard;

   

    case thing of

        (* CAUSES ERROR  cpu:             writeln('test'); *)

        mouse..monitor:  writeln('peripheral');

        cpu:             writeln('processor');

    end;

   

            while num1 < 10 do

            begin

             

                if (num1 < 5) then

                     write('tiny ')

                else

                     write('huge ');

                    

                case num1 of

                  1:     write('uno ');

                  2,6,8: write('doseiocho ');

                  3..5:  write('trequacinco ');

                  7:     write('siete ');

                  9:     write('nueve ');

                  10:    write('dies ');

                end;

               

                writeln('hello');

                num1 := num1 + 1

               

            end

end.