Records · Enregistrements
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.
Différents types sous un même nom
- AS sujet 10.1 demande de définir un enregistrement : un identifiant unique contenant des champs de différents types.
TYPE…ENDTYPEnomme l'enregistrement et déclare chaque champ.- Ce n'est pas une classe A2. Il n'y a pas de méthodes ici.
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 champ se lit avec un point
S.Nameest le champNamedeS.- Vous pouvez copier tout un enregistrement :
Pupil2 ← Pupil1copie tous les champs. - Un tableau d'enregistrements utilise un index, puis le champ :
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.
Attention
- Déclarez la structure
TYPEavant de déclarerDECLAREune variable de ce type. - Les types énumérés et les pointeurs sont du programme A2 (sujet 13.1). Ils ne font pas partie de ce cours AS.
Common mistakes
- Each field has its own
DECLAREinside theTYPE. ENDTYPEcloses the definition. Forgetting it leaves the type unfinished.
Erreurs courantes
- Chaque champ possède son propre
DECLAREà l'intérieur de la structureTYPE. ENDTYPEferme la définition. L'oublier laisse le type inachevé.
Now you try
- Define a record, store two fields, and output them.
À vous maintenant
- Définir un enregistrement, stocker deux champs, et les afficher.
Define a Student record with Name and · et Mark. Store Ada and · et 91, and output Ada 91. · Définissez un enregistrement Student avec Name et Mark. Stockez Ada et 91, et affichez Ada 91.
Click Run to see the output here. · Cliquez sur Exécuter pour voir le résultat ici.
An array Form of two students is partly filled below. Store Bo as the second name and output it. · Un tableau Form de deux étudiants est partiellement rempli ci-dessous. Stockez Bo comme second nom et affichez-le.
Click Run to see the output here. · Cliquez sur Exécuter pour voir le résultat ici.
The array Form of two students is filled in below. Add up Form[1].Mark and · et Form[2].Mark with a FOR loop and output the total (171). · Le tableau Form de deux étudiants est rempli ci-dessous. Additionnez Form[1].Mark et Form[2].Mark avec une boucle FOR et affichez le total (171).
Click Run to see the output here. · Cliquez sur Exécuter pour voir le résultat ici.