Lesson 79: Records
עמוד זה דורש דפדפן עדכני (תומך ב-SharedArrayBuffer). אנא עדכן את Chrome, Edge, Firefox או Safari לגרסה העדכנית ביותר.
English
Fields that belong together
- A record is a composite data type: one item made of several fields, which can have different data types.
- In C++ you define a record type with
struct. Then you can make variables and arrays of that type. - You reach a field with a dot:
team[1].name.
| Pseudocode (9618) | C++ |
|---|---|
| TYPE Player | struct Player { |
| DECLARE Name : STRING | String name; |
| DECLARE Score : INTEGER | int score; |
| ENDTYPE | }; |
- An array of records replaces parallel arrays (Robots lesson 48): the name and the score can never get out of step.
English
In the exam
- 9618/32/M/J/23 Q6(a): declare the composite data type TAppointments for patients of a dental clinic (name, date of birth, telephone number, last and next appointment, treatments complete yes or no). Mark scheme: TYPE TAppointments … ENDTYPE, with a DECLARE for each field, e.g. Telephone : STRING and TreatmentsComplete : BOOLEAN. (b) An array of these records: DECLARE DentalRecord : ARRAY[1:250] OF TAppointments.
רמת קושי 3/5 · 200 מטבעות + בונוס קטן בהשלמה הראשונה היום
A record keeps several fields about one thing together, even of different data types. In C++ a record type is a struct. Player has only the field name, so the program does not compile. Add the field score (an int) and the field online (a bool).
לחץ על הרץ כדי לראות את התוצא כאן.
רמת קושי 4/5 · 280 מטבעות + בונוס קטן בהשלמה הראשונה היום
Type 4 players as name,score, for example Ana,120. Store each one in the next record of team, then, after 4, print the player with the highest score: Top: Eli 150.
לחץ על הרץ כדי לראות את התוצא כאן.