1. Preliminary
In Pascal, modular programming can be done in a variety of methods. Among the modules in one program, or in a separate module from the main program file. in a separate module, can be made unit which is a separate library. While in one program, can use the procedure or function. The use of the procedure have been discussed in previous modules.
Function is not much different than the procedure, because it is a sub-program implementation. However, the function must be declared with the type. Type shows the type of result declaration of the function. Type the dtulis at the end of the function declaration, which is preceded by a semicolon. Function blocks together with block procedure Begin backup word that begins and ends with the word End reserves and a semicolon.
At the function, the value passed back there in the name of the function (for the procedure, the parameters passed by reference). The name of the function must be used to accommodate the results of which will be sent from the function. Because the return value is in the name of the function, the function can be directly used to print the results, or value of the function can also be directly transferred to another variable identifier. While the procedure, the procedure name can not be used directly, which can be directly used is the parameter that contains the return value.
2. The word used reserve
Program: The specification name of the program and its parameters, is decorative and not affect the overall program itself Uses: define the name of the unit to be referenced by the program Var: linking an identifier and its type with a location in memory where the values of these types can be stored Function: the programs that do koputasi and return a value Begin: starting a program block End: end a program block If: mention the conditions for a statement that can be executed Then: mention the statement of action must be executed when the conditions are met Else: mention the statement of actions that can be executed while another action statement is not executed because the condition is not fulfilled. Repeat: define statement or block of statements that will be repeated until the state stops filled Until: defines the state of rest for the loop that begins with the Repeat Do: used to describe the action to perform For: defines the initial value iteration To: defines the value of the final iteration (iteration positive)
3. The procedure used
Write: writing a variable into a component file in a text file used to write one or more values to a file Writeln: executing the write procedure, then pulled out a marker of end-of-line (EOL) to the program files Read: read a file into a variable component, in a text file used to read one or more values into one or more variables Readln: executes a read procedure, and then move to the next line in program files
4. Functions used
Exp: to calculate the value of ex Ln: Ln standard function to calculate the value of Ln X
1. SIMPLE PROGRAM
a. Program pertama
Program m8c1;
Uses wincrt;
Function hitung(var a, b, c : integer): integer;
Begin
Hitung := a + b;
c := a * b;
End;
Var
x, y, z : integer;
Begin
write ('Nilai x? ');
readln (x);
write ('Nilai y? ');
readln (y);
writeln;
writeln (x, ' + ', y, ' = ', hitung(x,y,z));
writeln (x, ' x ', y, ' = ', z);
End.