mirror of
https://github.com/vishapoberon/oberonbyexample.git
synced 2026-04-05 21:02:25 +00:00
intro to records
This commit is contained in:
parent
9bcdd6db33
commit
611ca27c17
1 changed files with 53 additions and 0 deletions
53
records/Records.Mod
Normal file
53
records/Records.Mod
Normal file
|
|
@ -0,0 +1,53 @@
|
||||||
|
MODULE record;
|
||||||
|
|
||||||
|
|
||||||
|
IMPORT Out;
|
||||||
|
|
||||||
|
|
||||||
|
CONST
|
||||||
|
Male = 1;
|
||||||
|
Female = 2;
|
||||||
|
|
||||||
|
|
||||||
|
TYPE
|
||||||
|
SexDesc = INTEGER;
|
||||||
|
Person = RECORD
|
||||||
|
Name : ARRAY 32 OF CHAR;
|
||||||
|
Age : INTEGER;
|
||||||
|
Title : ARRAY 64 OF CHAR;
|
||||||
|
Sex : SexDesc;
|
||||||
|
END;
|
||||||
|
|
||||||
|
|
||||||
|
VAR
|
||||||
|
i : INTEGER;
|
||||||
|
employer : Person;
|
||||||
|
employee : ARRAY 2 OF Person;
|
||||||
|
|
||||||
|
|
||||||
|
PROCEDURE dumpPerson ( p : Person );
|
||||||
|
BEGIN
|
||||||
|
Out.String("Meet "); Out.String(p.Name);
|
||||||
|
IF p.Sex = Male THEN Out.String(". He is ") END;
|
||||||
|
IF p.Sex = Female THEN Out.String(". She is ") END;
|
||||||
|
Out.Int(p.Age, 0); Out.String(" years old and a "); Out.String(p.Title); Out.Ln;
|
||||||
|
END dumpPerson;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
BEGIN
|
||||||
|
(* define people *)
|
||||||
|
employer.Name := "Bing"; employer.Age := 42; employer.Title := "CEO"; employer.Sex := Male;
|
||||||
|
|
||||||
|
employee[0].Name := "Bob"; employee[0].Age := 26;
|
||||||
|
employee[0].Title := "SysAdmin"; employee[0].Sex := Male;
|
||||||
|
|
||||||
|
employee[1].Name := "Alice" ; employee[1].Age := 22;
|
||||||
|
employee[1].Title := "Programmer"; employee[1].Sex := Female;
|
||||||
|
|
||||||
|
(* print people *)
|
||||||
|
dumpPerson(employer);
|
||||||
|
FOR i := 0 TO LEN(employee) - 1 DO
|
||||||
|
dumpPerson(employee[i]);
|
||||||
|
END;
|
||||||
|
END record.
|
||||||
Loading…
Add table
Add a link
Reference in a new issue