1. Preliminary When making a program, and the program includes a declaration of identifier variables in the program, then these variables must be declared first. When making the declaration of variables, also have determined the type of data used. This data type indicates a value that can be used by these variables, in other words, this type determines the value that can be stored by the variable. In addition to value, also saved the operators that can be performed on the data type. Data can be stored in the form of constant or in a variable. Constants are stored in the identifier constants and their values have not changed in the program. The data stored in a variable value can be changed in the program. There are many different types of data that can be used in programs written in Pascal language. Among them is the ordinal type (composed of type integer, boolean type, character type, the type spelled out, and subrange type), type real, string type, array type, record type, set type, file type, and type of pointer. Operators that can be used such as +, -, *, /, div, mod, music, and, or, xor, SHL, shr, =, <>, <,>, <=,> =, and ins.
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 Begin: starting a program block End: end a program block In: operators who provide operational "members of" And: An operator that provides logic operations "and" Or: An operator that provides logic operations "or" Div: operator for the division and rounding the result down Mod: operator for the division and give the rest of her results SHL: operator to shift a bit to the left Shr: operator to shift a bit to the right Note: the service logic operation to reverse the status Xor: operator XOR logic operation 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 Sqr: square value of an argument Sqrt: root value of an argument
1. ex.program
a. Contoh pertama
Program m2c1;
Uses wincrt;
Var
a, b, c : real;
Begin
writeln ('Menghitung panjang sisi miring segitiga');
write ('Nilai tinggi? ');
readln (a);
write ('Nilai alas? ');
readln (b);
c := sqrt (sqr(a) + sqr(b));
writeln ('Panjang sisi miring adalah:',c:5:2);
End.
b. Contoh ke-dua
Program m2c2;
Uses wincrt;
Var
C, R, F : real;
Begin
Write (‘Masukkan suhu dalam Celcius: ’);
Readln (C);
R := (4/5) * C;
F := (9/5) * C + 32;
Writeln;
Writeln (‘Suhu dalam Reamur: ‘, R:5:2);
Writeln (‘Suhu dalam Fahrenheit: ‘, F:5:2);
End.
c. Contoh ke-tiga
Program m2c3;
Uses wincrt;
Var
j1,j2,m1,m2,d1,d2,det1,det2,delta,j,m,d : integer;
Begin
Write (‘Jam mulai: ’);
Readln (j1,m1,d1);
Write (‘Jam berhenti: ’);
Readln (j2,m2,d2);
det1 := (j1 * 3600) + (m1 * 60) + d1;
det2 := (j2 * 3600) + (m2 * 60) + d2;
delta := det2 – det1;
j := delta div 3600;
delta := delta mod 3600;
m := delta div 60;
d := delta mod 60;
Writeln (‘Selisih jam : ’, j, ‘:’, m, ‘:’, d);
End.
d. Contoh ke-empat
Program m2c4;
Uses wincrt;
Var
a, b : integer;
Begin
Write (‘Masukkan nilai a dan b: ’);
Readln (a, b);
Writeln (‘a * b = ’,a * b);
Writeln (‘a / b = ’,a / b :4:2);
Writeln (‘a div b = ’,a div b);
Writeln (‘a mod b = ’,a mod b);
Writeln (‘Not a = ’, not a, ‘ Not b = ’,not b);
Writeln (‘a and b = ’,a and b);
Writeln (‘a or b = ’,a or b);
Writeln (‘a xor b = ’,a xor b);
Writeln (‘a shr b = ’,a shr b);
Writeln (‘a shl b = ’,a shl b);
End.
Tidak ada komentar:
Posting Komentar