Kamis, 20 Januari 2011

MAKE SIMPLE PROGRAM

SIMPLE PROGRAM 
  1. Preliminary Structure of a Pascal program consists of a title of the program (program heading) and a block of the program (program block) or agency program (program body). Block program is further divided into 2 parts, namely the declaration (declaration part) and the statement (statement part). Declaration section can consist of the declaration label (labels declaration), the declaration of constants (constants declaration), the declaration type (type declarations), variable declarations (variables declarations), the declaration procedure (declaration procedures), and function declarations (function declaration). Pascal program does not know the rules of writing in a particular column, so it should be written from any column. Writing the statement-the statement in the example program that juts into several columns have no effect on the process, only intended to facilitate the reading program, so it will be more visible parts. Writing Pascal programs can even be connected whole in a single line, provided it does not forget the sign of the end of each command. But the writing is not recommended and should be avoided, because it is not good for the program documentation and difficult to read or trace if something goes wrong.
2. The word used reserve Below is a reserve words (reserved words) that will be frequently used in practice using the language Pascal in this module. 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 Const: define the identifier which has a fixed value in the block declaration 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
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 file. 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. Sample Program Store the source code of this program in your own folder or in My Documents folder (recommended), with appropriate file name program name an example (do not forget to PAS extension on each program source code.) 



a.       Contoh pertama
Program m1c2;
Uses wincrt;
Begin
      Write (‘Latihan saya yang pertama ’);
      Writeln (‘adalah menulis kalimat ini’);
      Writeln (‘di layar monitor.’);
      Writeln (‘Keseluruhannya ada berapa baris?’);
End.

b.      Contoh ke-dua
Program m1c1;
Uses wincrt;
Var
      A, B, D, E : integer;
Const
      C = 100;
Begin
      Write (‘Nilai bilangan pertama? ’);
      Readln (A);
      Write (‘Nilai bilangan ke-dua? ’);
      Readln (B);
      Writeln;
      D := A + B;
      E := D * C;
      Writeln (‘Hasil penjumlahan A dan B adalah ’,D);
      Writeln (‘Bila dikalikan dengan 100 adalah ’,E);
End.

c.       Contoh ke-tiga
Program m1c3;
Uses wincrt;
Var
      X : integer;
Begin
      Write (‘Masukkan suatu bilangan: ’);
      Readln (X);
      Writeln;
      Writeln (X, ‘ mod 2 = ’, X mod 2);
      Writeln;
      Write (‘Operasi apakah yang baru saja Anda lakukan, ’);
      Writeln (‘dan apakah kesimpulan Anda?’);
End.

d.      Contoh ke-empat
Program m1c4;
Uses wincrt;
Const
      Phi = 3.14;
Var
      Radius, Luas : real;
Begin
      Write (‘Nilai Radius ? ’);
      Readln (Radius);
      Luas := Phi * Radius * Radius;
      Writeln;
      Writeln (‘Luas Lingkaran = ’, Luas);
      Writeln;
      Write (‘Tekan tombol Enter untuk menghentikan program’);
Readln;
End.

Tidak ada komentar:

Posting Komentar