Computer Science Canada
|Author:||Schaef [ Tue Jan 20, 2004 7:13 am ]|
|Post subject:||procedure help|
I was just wondering in a procedure what the things in the bracket are after proc and the name of the procedure and why the variables do not need to be assigned values
|Author:||CjGaughan [ Tue Jan 20, 2004 10:38 am ]|
A part of a program (a subprogram) can be given a name. There are two kinds of subprograms:
There are subprograms that are predefined (provided as part of the Turing language).
-sqrt -- a predefined function that gives the square root of a number.
randint - a predefined procedure that generates random integers
A function takes a value, such as 3, and produces a result, such as 9. In this example, the function produces the square of the number it receives; so when it receives 3 it produces 3**2 = 9
function square (x : real) : real
for i : 1 .. 5
put i : 2, square (i) : 4
We say that the square function is called and that actual parameter i is passed to formal parameter x.
AN EXAMPLE FUNCTION
The function shown here takes a name such as "fred jones" and produces a result string with the last name first : "Jones, Fred"
basically, the part in the brackets is the kind of variable that will be used for input.
here is an example code (calculates area of a circle):
dont know if this helps...but oh well