records

13
Records Dasar Pemrograman

Upload: desirae-lancaster

Post on 01-Jan-2016

17 views

Category:

Documents


0 download

DESCRIPTION

Records. Dasar Pemrograman. RECORDS. Record data types—a complex type that combines different data types into a single record. Sometimes called set types. The individual elements of a record are called fields or components or component fields. RECORDS. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Records

Records

Dasar Pemrograman

Page 2: Records

RECORDS

Record data types—a complex type that combines different data types into a single record.

Sometimes called set types. The individual elements of a record are

called fields or components or component fields.

Page 3: Records

Each field has a name . . .the field identifier. The field identifiers provide a means of

accessing each field in the record, similar to an array index.

Each field has a type, which is established when the record is declared.

The value of a record is a collection of values. There is a value in each field.

RECORDS

Page 4: Records

RECORDS

The component of a record variable is a component variable.

. field identifier . . .specifies a component variable.–e g: Business1.PresidentsLastName

Though a record is a collection of values, it can sometimes be treated as a single value.

Page 5: Records

RECORDS

So . . .– The record variable describes the raw

record.– Record value indicates all the values in

the record.– Component values indicate the field

values.– Field identifiers name the fields in record.

Page 6: Records

Syntax

type– Business =

• record– BusinessName: string[30];– StreetAddress: string[35]– City: string[20];– State: string[2];– zip: integer;

• end;

Page 7: Records

A programmer may want to structure data with a hierarchy of records.

e g:– student identification– birth date and age– core courses . . .etc . . .

Page 8: Records

Data Structures

Records for a group may be read into an array.

Thus, we see that . . .– data structures are a means of

organizing, storing and manipulating data. How do we chose which structure to

use?– Everything being equal, chose the one that can be

understood and worked with most easily.

Page 9: Records

If all items are of the same type . . .a single array of that type works best.

If items differ in type, use an array of records.

Options…

Page 10: Records

with statements . . .

With provides instruction(s) to carry out an operation.

Syntax– with record_variable_list do

• statement (usually compound)

The records_variable_list is separated by commas.

Page 11: Records

with statements . . .

Instead of writing the syntax like this:Data.npm :=‘22297566’

Data.Nama:=‘Abdul Kadir’

Data.Fakultas:=‘Teknik’

We can replace using with expression:WITH Data Do

Begin

npm :=‘22297566’

Nama:=‘Abdul Kadir’

Fakultas:=‘Teknik’

end;

Page 12: Records

Example of array of record

Page 13: Records

Example of record of arrayType barang= RECORD

nmbrg:string[20];

jmlbrg:array[1..3]of byte;

hrgbrg:real;

total:real;

end;

var jual:barang;

tbarang, i:integer;

Begin

clrscr;

write(‘Nama Barang :’);readln(jual.nmbrg);

for i:=1to 3 do

begin

write(‘Jumlah barang ’,I,’ : ’);readln(jual.jmlbrg[i]);

tbarang:=tbarang+jual.jmlbrg[i];

end;

write(‘Harga barang :’);readln(jual.hrgbrg);

jual.total:=tbarang*jual.hrgbrg;

writeln(‘Total Harga Barang = ‘, jual.total:10:2);

end.