next up previous
Next: 3 A Sequence Recognizer Up: APS105F Friday Quiz 1 Previous: 1 Drawing Dots

2 Function Values

A function is defined as follows:

The complete program computes the values of the function within a specified interval, Xmin to Xmax, using the specified step size, Xstep, i.e. compute the function at the values Xmin, Xmin + Xstep, Xmin + 2*Xstep, ..., Xmax.

The file /usr/copy/aps105/funcs.t contains the code that does most of this. There are two modules that do not exist: GetParameters, and Compute. The GetParameters module gets the three parameters as input. You may assume that only real numbers in the correct range will be input for these parameters. The Compute module returns the value of the function based on its input parameter.

The code in funcs.t reads as follows:

loop
    var Xmin,Xmax,Xstep,X : real
    var Y : real

    GetParameters(Xmin,Xmax,Xstep)
    exit when Xstep = 0

    X := Xmin

    loop
        var temp : real

        Y := Compute(X)
        put X:8:3,"  ",Y:8:3
        temp := X + Xstep
        exit when temp > Xmax
        X := temp
    end loop

    if X not= Xmax then
        Y := Compute(Xmax)
        put Xmax:8:3,"  ",Y:8:3
    end if
end loop

You may include the code of funcs.t either by copying from the file /usr/copy/aps105/funcs.t

into your file ``part2.t'' or by simply having the statement include "/usr/copy/aps105/funcs.t"

after the declaration of your modules.

Restrictions:

The modules you write may not use any global variables and they are not to output anything. You may not change the code you import from funcs.t in any way.

A solution


Paul Chow
Sun Oct 27 10:55:46 EST 1996