Records · Catatan (Records)
Different types under one name
- AS topic 10.1 asks you to define a record: one identifier holding fields of different types.
TYPE…ENDTYPEnames the record and declares each field.- This is not an A2 class. There are no methods here.
Tipe berbeda di bawah satu nama
- AS topik 10.1 meminta Anda mendefinisikan rekaman: satu pengenal yang memegang bidang dengan tipe berbeda.
TYPE…ENDTYPEmemberi nama rekaman dan mendeklarasikan setiap bidang.- Ini bukan kelas A2. Tidak ada metode di sini.
TYPE Student
DECLARE Name : STRING
DECLARE Mark : INTEGER
ENDTYPE
DECLARE S : Student
S.Name ← "Ada"
S.Mark ← 91
OUTPUT S.Name & " " & S.Mark
A field is read with a dot
S.Nameis theNamefield ofS.- You may copy a whole record:
Pupil2 ← Pupil1copies every field. - An array of records uses one index, then the field:
Form[1].Mark.
Bidang dibaca dengan titik
S.Nameadalah bidangNamedariS.- Anda dapat menyalin seluruh rekaman:
Pupil2 ← Pupil1menyalin setiap bidang. - Array rekaman menggunakan satu indeks, lalu bidang:
Form[1].Mark.
TYPE Student
DECLARE Name : STRING
DECLARE Mark : INTEGER
ENDTYPE
DECLARE Form : ARRAY[1:2] OF Student
Form[1].Name ← "Ada"
Form[1].Mark ← 91
Form[2].Name ← "Bo"
Form[2].Mark ← 80
OUTPUT Form[2].Name
Watch out
- Declare the
TYPEbefore youDECLAREa variable of that type. - Enumerated types and pointers are A2 (topic 13.1). They are not in this AS course.
Hati-hati
- Deklarasikan
TYPEsebelum AndaDECLAREvariabel dari tipe itu. - Tipe terenumerasi dan pointer adalah A2 (topik 13.1). Mereka tidak ada dalam kursus AS ini.
Common mistakes
- Each field has its own
DECLAREinside theTYPE. ENDTYPEcloses the definition. Forgetting it leaves the type unfinished.
Kesalahan umum
- Setiap bidang memiliki
DECLAREsendiri di dalamTYPE. ENDTYPEmenutup definisi. Melupakannya meninggalkan tipe belum selesai.
Now you try
- Define a record, store two fields, and output them.
Sekarang Anda coba
- Definisikan rekaman, simpan dua bidang, dan tampilkan mereka.
Define a Student record with Name and Mark. Store Ada and 91, and output Ada 91. · Definisikan catatan Student dengan Name dan Mark. Simpan Ada dan 91, dan outputkan Ada 91.
Click Run to see the output here. · Klik Jalankan untuk melihat output di sini.
An array Form of two students is partly filled below. Store Bo as the second name and output it. · Sebuah array Form berisi dua siswa sebagian terisi di bawah ini. Simpan Bo sebagai nama kedua dan outputkan.
Click Run to see the output here. · Klik Jalankan untuk melihat output di sini.
The array Form of two students is filled in below. Add up Form[1].Mark and Form[2].Mark with a FOR loop and output the total (171). · Array Form berisi dua siswa dan diisi di bawah ini. Jumlahkan Form[1].Mark dan Form[2].Mark menggunakan perulangan FOR, lalu tampilkan totalnya (171).
Click Run to see the output here. · Klik Jalankan untuk melihat output di sini.