Kamis, 20 Januari 2011

RECORD AND ARRAY OF RECORD

RECORD & ARRAY OF RECORD


1. Preliminary Using the array, you can only save the values you entered into the memory during the program running in the same type. For example, you will not be able to save data in addition to integer form if you already have an array defined as type integer. So you can store various types of data when your program runs, you need other mechanisms to do this in Pascal, in this case is a record. With records, you can store a value in the form of integer, real, char, string, or other data types together. This program allows users to store various data simultaneously for the program is still running, and can use the data for various purposes. To note, the record usually consists of several fields only, making it difficult to use to store data in a number of arrays. This is because there is no mechanism in the record index. For that use a combination of arrays and records, called with an array of records. Array of records makes it possible to store more data (as much as the array index), each containing data 'property' which consists of various types of data (as many fields from record). Because it is very important to master an array of records as a basis for programming that involves a lot of data at once which consists of various types of data. If this section has been mastered, you are ready to manipulate the data even further through a programming using Pascal.
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 Array: used to define an array type Record: used to declare the record contains a collection of data from various types of data With: used to make reference to a field in the record Type: used to declare an identifier that has a specific data type Do: used to describe the action to perform For: defines the initial value iteration To: defines the value of the final iteration (iteration positive) 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.
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 Readkey: read a character entered through keyboard 



a.       Contoh pertama
Program m6c1;
uses wincrt;
type
     anggota = record
         nama   : string[20];
         alamat : string[30];
         jenkel, status : char;
         umur   : byte;
     end;
var
     peserta : anggota;
     tampil  : char;
     stat    : string[15];
     kel     : string[9];
begin
     writeln;
     writeln ('DATA PESERTA');
     writeln;
     write ('Nama : ');
     readln (peserta.nama);
     write ('Alamat : ');
     readln (peserta.alamat);
     write ('Jenis kelamin (L/P) : ');
     readln (peserta.jenkel);
     If (peserta.jenkel = 'L') or (peserta.jenkel = 'l') then
          kel := 'Laki-laki'
     else
          kel := 'Perempuan';
     write ('Umur : ');
     readln (peserta.umur);
     write ('Menikah (Y/T) : ');
     readln (peserta.status);
     If (peserta.status = 'Y') or (peserta.status = 'y') then
          stat := 'Menikah'
     else
          stat := 'Tidak menikah';
     writeln;
     write ('Tampilkan data (Y/T)? ');
     tampil := readkey;
     writeln;
     If (tampil = 'Y') or (tampil = 'y') then
     begin
          writeln;
          writeln('Nama          : ',peserta.nama);
          writeln('Alamat        : ',peserta.alamat);
          writeln('Jenis Kelamin : ',kel);
          writeln('Umur          : ',peserta.umur,' tahun');
          writeln('Status        : ',stat);
     end;
end.

b.      Contoh ke-dua
Program m6c2;
uses wincrt;
type
     databrg = record
             namabrg : string[15];
             unitbrg : byte;
     end;
var
     jumlahbrg, i : integer;
     total : word;
     barang : array [1..20] of databrg;
begin
     writeln;
     write ('Jumlah barang? ');
     readln (jumlahbrg);
     for i := 1 to jumlahbrg do
     begin
          writeln;
          writeln ('Barang ke ',i);
          with barang[i] do
          begin
               write ('Nama barang : ');
               readln (namabrg);
               write ('Unit : ');
               readln (unitbrg);
          end;
     end;
     writeln;
     writeln ('=========================');
     writeln ('     INVENTARIS DATA');
     writeln ('=========================');
     total := 0;
     for i := 1 to jumlahbrg do
     begin
          with barang[i] do
          begin
               total := total + unitbrg;
               writeln (namabrg:15, unitbrg:5);
          end;
     end;
     writeln;
     writeln ('******** Total: ',total:4);
end.

1 komentar: