Type Data Record

(*contoh pertama:*)

uses crt;
type
alamat = record
jln : string[20];
no : string[3];
kota : string[20];
kdpos : string[6];
end;
datamhs = record
nama : string[15];
npm : string[8];
almt : alamat;
jk : char;
gldrh : string[2];
end;
var
dataku : datamhs;
begin
clrscr;
with dataku, almt do
begin
write(‘Nama : ‘); readln(nama);
write(‘NPM : ‘); readln(npm);
writeln(‘ Alamat ‘);
write(‘Jalan : ‘); readln(jln);
write(‘Nomor : ‘); readln(no);
write(‘Kota : ‘); readln(kota);
write(‘Kode Pos : ‘); readln(kdpos);
write(‘Jenis Kelamin (L/P) : ‘); readln(jk);
write(‘Golongan Darah : ‘); readln(gldrh);
end;
clrscr;
with dataku, almt do
begin
gotoxy(9,5);writeln(‘ B I O D A T A K U ‘);
gotoxy(7,7);writeln(‘Nama Saya ‘,nama);
gotoxy(7,8);writeln(‘NPM Saya ‘,npm);
gotoxy(7,9);writeln(‘Jenis Kelamin ‘,jk);
gotoxy(7,10);writeln(‘Golongan Darah ‘,gldrh);
gotoxy(7,11);writeln(‘Alamat Saya : Jalan ‘,jln,’ Nomor ‘,no,’ ,kota,’ ‘,kdpos);
end;
readln;
end.

http://one.indoskripsi.com/judul-skripsi-tugas-makalah/algoritma/tugas-algoritma-2

(*contoh kedua:

Passing Records as Arguments*)

Type
Str25 = String[25];
TBookRec = Record
Title, Author,
ISBN : Str25;
Price : Real;
End;

Procedure EnterNewBook(var newBook : TBookRec);
Begin
Writeln(‘Please enter the book details: ‘);
Write(‘Book Name: ‘);
Readln(newBook.Title);
Write(‘Author: ‘);
Readln(newBook.Author);
Write(‘ISBN: ‘);
Readln(newBook.ISBN);
Write(‘Price: ‘);
Readln(newBook.Price);
End;

Procedure DisplayBookDetails(myBookRec : TBookRec);
Begin
Writeln(‘Here are the book details:’);
Writeln;
Writeln(‘Title: ‘, myBookRec.Title);
Writeln(‘Author: ‘, myBookRec.Author);
Writeln(‘ISBN: ‘, myBookRec.ISBN);
Writeln(‘Price: ‘, myBookRec.Price);
End;

Var
bookRec : TBookRec;

Begin
EnterNewBook(bookRec);
Writeln(‘Thanks for entering the book details’);
DisplayBookDetails(bookRec);
Readln;
End.

(*contoh ketiga:

Array Of Records*)

Type
Str25 = String[25];
TBookRec = Record
Title, Author,
ISBN : Str25;
Price : Real;
End;

Procedure EnterNewBook(var newBook : TBookRec);
Begin
Writeln(‘Please enter the book details: ‘);
Write(‘Book Name: ‘);
Readln(newBook.Title);
Write(‘Author: ‘);
Readln(newBook.Author);
Write(‘ISBN: ‘);
Readln(newBook.ISBN);
Write(‘Price: ‘);
Readln(newBook.Price);
End;

Var
bookRecArray : Array[1..10] of TBookRec;
i : 1..10;

Begin
For i := 1 to 10 do
EnterNewBook(bookRecArray[i]);
Writeln(‘Thanks for entering the book details’);
Write(‘Now choose a record to display from 1 to 10: ‘);
Readln(i);
Writeln(‘Here are the book details of record #’,i,’:’);
Writeln;
Writeln(‘Title: ‘, bookRecArray[i].Title);
Writeln(‘Author: ‘, bookRecArray[i].Author);
Writeln(‘ISBN: ‘, bookRecArray[i].ISBN);
Writeln(‘Price: ‘, bookRecArray[i].Price);
Readln;
End.

(*contoh keempat:

Binary File and Records*)

Type
Str25 = String[25];
TBookRec = Record
Title, Author,
ISBN : Str25;
Price : Real;
End;

Procedure EnterNewBook(var newBook : TBookRec);
Begin
Writeln(‘Please enter the book details: ‘);
Write(‘Book Name: ‘);
Readln(newBook.Title);
Write(‘Author: ‘);
Readln(newBook.Author);
Write(‘ISBN: ‘);
Readln(newBook.ISBN);
Write(‘Price: ‘);
Readln(newBook.Price);
End;

Var
bookRecArray : Array[1..10] of TBookRec;
tempBookRec : TBookRec;
bookRecFile : File of TBookRec;
i : 1..10;

Begin
Assign(bookRecFile, ‘bookrec.dat’);
ReWrite(bookRecFile);
For i := 1 to 10 do
Begin
EnterNewBook(bookRecArray[i]);
{ bookRecArray[i] now contains the book details }
Write(bookRecFile, bookRecArray[i]);
End;
Close(bookRecFile);
Writeln(‘Thanks for entering the book details.’);
Writeln(‘They are saved in a file!’);
Write(‘Now choose a record to display from 1 to 10: ‘);
Readln(i);
ReSet(bookRecFile);
Seek(bookRecFile, i-1);
Read(bookRecFile, tempBookRec);
Close(bookRecFile);
Writeln(‘Here are the book details of record #’,i,’:’);
Writeln;
Writeln(‘Title: ‘, tempBookRec.Title);
Writeln(‘Author: ‘, tempBookRec.Author);
Writeln(‘ISBN: ‘, tempBookRec.ISBN);
Writeln(‘Price: ‘, tempBookRec.Price);
Readln;
End.

http://pascalprogramming.byethost15.com

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s