Records · Registros
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.
Diferentes tipos bajo un mismo nombre
- El tema 10.1 de AS te pide definir un registro: un identificador que contiene campos de diferentes tipos.
TYPE…ENDTYPEnombra el registro y declara cada campo.- Esto no es una clase A2. Aquí no hay métodos.
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.
Un campo se lee con un punto
S.Namees el campoNamedeS.- Puedes copiar todo un registro:
Pupil2 ← Pupil1copia todos los campos. - Un array de registros usa un índice y luego el campo:
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.
Ten cuidado
- Declara el
TYPEantes deDECLAREuna variable de ese tipo. - Los tipos enumerados y los punteros son de A2 (tema 13.1). No están en este curso de AS.
Common mistakes
- Each field has its own
DECLAREinside theTYPE. ENDTYPEcloses the definition. Forgetting it leaves the type unfinished.
Errores comunes
- Cada campo tiene su propio
DECLAREdentro delTYPE. ENDTYPEcierra la definición. Olvidarlo deja el tipo incompleto.
Now you try
- Define a record, store two fields, and output them.
Ahora tú intentas
- Define un registro, almacena dos campos e imprímelos.
Define a Student record with Name and · y Mark. Store Ada and · y 91, and output Ada 91. · Define un registro Student con Name y Mark. Almacena Ada y 91, y emite Ada 91.
Click Run to see the output here. · Haz clic en Ejecutar para ver la salida aquí.
An array Form of two students is partly filled below. Store Bo as the second name and output it. · Un array Form de dos estudiantes está parcialmente lleno a continuación. Almacena Bo como el segundo nombre y emítelo.
Click Run to see the output here. · Haz clic en Ejecutar para ver la salida aquí.
The array Form of two students is filled in below. Add up Form[1].Mark and · y Form[2].Mark with a FOR loop and output the total (171). · El array Form de dos estudiantes está lleno a continuación. Suma Form[1].Mark y Form[2].Mark con un bucle FOR y emite el total (171).
Click Run to see the output here. · Haz clic en Ejecutar para ver la salida aquí.