{"id":210,"date":"2022-01-20T15:55:25","date_gmt":"2022-01-20T14:55:25","guid":{"rendered":"https:\/\/wiskunst.hjgsoft.nl\/?page_id=210"},"modified":"2022-01-24T09:36:55","modified_gmt":"2022-01-24T08:36:55","slug":"gestructureerde-types","status":"publish","type":"page","link":"https:\/\/wiskunst.nl\/index.php\/programmeren1\/programmeren\/gestructureerde-types\/","title":{"rendered":"Gestructureerde types"},"content":{"rendered":"<p>We hebben al een aantal keer (gedwongen) gebruik gemaakt van een type-declaratie voor strings.<br \/>\nPascal kent het principe van zelfgemaakte types.<br \/>\nIn hoofdstuk 8 (of 9) hebben we hier een paar voorbeelden van gezien.<br \/>\nIn dit hoofdstuk gaan we ons bezig houden met gestructureerde types.<br \/>\nDeze versie van Pascal kent twee gestructureerde types, nl. de\u00a0<b>array<\/b>\u00a0en de\u00a0<b>record<\/b>.<br \/>\nIn latere versies (waaronder Delphi) is daar een derde bijgekomen, nl. de\u00a0<b>class<\/b>.<\/p>\n<h2>Array&#8217;s.<\/h2>\n<p>Een string is (wederom in deze versie van Pascal) een array van karakters.<br \/>\nHet voordeel van een array is dat je een (groot) aantal bij elkaar horende waardes effici\u00ebnt kan opslaan terwijl iedere waarde afzonderlijk benaderbaar blijft.<br \/>\nLaten we maar vlug naar het eerste voorbeeld gaan kijken:<\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">program\u00a0p12_1;<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">type<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 TDobbelsteen = array[1..6] of integer;<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">var<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Dobbelsteen: TDobbelsteen;<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">procedure\u00a0InitDobbelsteen(var\u00a0ds:\u00a0TDobbelsteen);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 var x: byte;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">begin<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 for x := 1 to 6 do<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 ds[x] := 0;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">end;<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">procedure\u00a0Gooi(aantal:\u00a0integer;var\u00a0ds:\u00a0TDobbelsteen);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 var<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 x: integer;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 w: byte;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">begin<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 for x := 1 to aantal do<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 begin<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 w := trunc(random * 6);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 ds[w] := ds[w] + 1;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 end;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">end;<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">procedure\u00a0Toon(ds:\u00a0TDobbelsteen);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 var x: byte;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">begin<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 for x := 1 to 6 do<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 write(x:8);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 writeln;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 for x := 1 to 6 do<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 write(ds[x]:8);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 writeln;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">end;<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">begin<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 randomize;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 InitDobbelsteen(Dobbelsteen);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Gooi(1000,Dobbelsteen);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Toon(Dobbelsteen);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">end.<\/span><\/p>\n<p>Het programma simuleert het 1000 keer gooien met een dobbelsteen en toont vervolgens hoe vaak iedere kant (1 t\/m 6) is gevallen.<br \/>\nIn dit voorbeeld wordt eerst een type\u00a0<b>TDobbelsteen<\/b>\u00a0gedeclareerd als een array met 6 elementen van het type integer.<br \/>\nVervolgens wordt een variabele\u00a0<b>Dobbelsteen<\/b>\u00a0van het zojuist gemaakte type TDobbelsteen gedeclareerd.<br \/>\nDe variabele Dobbelsteen is eigenlijk een bundeling van 6 integer-variabelen.<br \/>\nWanneer je een specifieke variabele uit Dobbelsteen wilt benaderen dan geef je z&#8217;n rangnummer tussen blokhaken aan.<br \/>\nAls ik hier bv. de waarde van 4-e variabele wil weten dan benader ik die met\u00a0<b>Dobbelsteen[4]<\/b>.<br \/>\nMet de functie\u00a0<b>random<\/b>\u00a0wordt een pseudo-willekeurig re\u00ebel getal tussen de 0 en 1 gekozen, waarbij 0 wel en 1 niet meedoet.<br \/>\nMet de functie\u00a0<b>trunc([getal])<\/b>\u00a0wordt alles achter de komma van\u00a0<i>getal<\/i>\u00a0afgekapt (dus niet afgerond!).<br \/>\nMet het commando\u00a0<b>randomize<\/b>\u00a0wordt de &#8216;randomizer&#8217; geschud, anders zou je bij iedere run van het programma dezelfde serie getallen krijgen.<br \/>\nDe rest van het programma moet duidelijk zijn.<br \/>\nOverigens is het in Turbo Pascal toegstaan om het array-type in de variabele-decalratie op te nemen.<br \/>\nHierboven zou je dus ook deze declaratie kunnen gebruiken:\u00a0<b>var Dobbelsteen: array[1..6] of integer<\/b>.<br \/>\nDit is weer niet toegestaan bij parameter-declaraties!<\/p>\n<p>Het voorbeeld hierboven maakte gebruik van een 1-dimensionale-array. Dit zeggende begrijpt de aandachte lezer dat er dus ook meer-dimensionale-array&#8217;s bestaan. En dat is juist.<br \/>\nIn het volgende voorbeeld gaan we kijken naar een 2-dimensionale array:<\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">program\u00a0p12_2;<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">const<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 dim = 5;<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">type<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 TMatrix = array[1..dim,1..dim] of integer;<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">var<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Matrix: TMatrix;<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">procedure\u00a0ToonMatrix(m:\u00a0TMatrix);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 var x,y: byte;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">begin<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 writeln;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 for x := 1 to dim do<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 begin<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 for y := 1 to dim do<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 \u00a0 write(m[x,y]:4);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 writeln;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 end;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">end;<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">procedure\u00a0VulMatrix(var\u00a0m:\u00a0TMatrix);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 var x,y: Byte;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">begin<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 for x := 1 to dim do<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 for y := 1 to dim do<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 m[x,y] := trunc(random*100);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">end;<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">begin<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 randomize;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 VulMatrix(Matrix);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 ToonMatrix(Matrix);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">end.<\/span><\/p>\n<p>Het enige wat dit programmaatje doet is een matrix van 5&#215;5 vullen met willekeurige getallen en vervolgens deze matrix op het scherm tonen.<br \/>\nIn dit programma heb ik gebruik gemaakt van een\u00a0<i>constante<\/i>-declaratie.<br \/>\nDe syntax luidt:<\/p>\n<p><b>const [naam] = [waarde];<br \/>\n<\/b><br \/>\nVervolgens kun je overal waar je iets van\u00a0<i>[waarde]<\/i>\u00a0wilt gebruiken revereren aan\u00a0<i>[naam]<\/i>.<br \/>\nMocht later blijken dat\u00a0<i>[naam]<\/i>\u00a0toch een andere waarde moet hebben, dan hoef je dat alleen maar in de\u00a0<i>constante<\/i>-declaratie-regel aan te passen.<br \/>\nIn het programma hierboven werken we dus met een variabele Matrix van 5&#215;5. Wat hier de x-dimensie en de y-dimensie is laat Pascal graag aan onze fantasie over.<br \/>\nIn principe kent Pascal geen beperkingen aan het aantal dimensies van array&#8217;s.<br \/>\nDe rest moet weer voor zich spreken.<\/p>\n<h2>Record&#8217;s.<\/h2>\n<p>Een record is een type met variabelen (in deze context\u00a0<i>velden<\/i>\u00a0genoemd) die logischerwijs bij elkaar horen.<br \/>\nDe syntax luidt:<\/p>\n<p><b>type<br \/>\n[naam] = record<br \/>\n[veld1]: [type_a];<br \/>\n[veld2],[veld3]: [type_b];<br \/>\n[veld4]: [type_c];<br \/>\nend;<br \/>\n<\/b><br \/>\nDus een record moet een naam hebben, en wordt omsloten met\u00a0<b>record<\/b>\u00a0en\u00a0<b>end;<\/b>.<br \/>\nHier binnen declareer je de velden (=variabelen) die je nodig hebt. De type&#8217;s van die velden mogen op hun beurt ook weer gestructureerd zijn.<br \/>\nIn het volgende voorbeeld gaan we stoeien met een NAW-record waar we NAW-gegevens van een persoon in gaan opslaan.<\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">program\u00a0P12_3;<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">type<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 s80 = string[80];<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 s40 = string[40];<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 s20 = string[20];<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 s15 = string[15];<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 s7 = string[7];<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 TNAW =<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 record<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 achternaam: s40;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 voorletters: s15;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 voornaam: s20;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 adres: s40;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 postcode: s7;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 plaats: s20;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 leeftijd: byte;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 geslacht: char;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 naamcombi: array[1..2] of s80<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 end;<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">var<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 NAW: TNAW;<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">procedure\u00a0LeesNAWIn(var\u00a0naw:\u00a0TNAW);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 var w: char;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">begin<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 write(&#8216;achternaam : &#8216;);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 readln(naw.achternaam);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 write(&#8216;voorletters: &#8216;);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 readln(naw.voorletters);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 write(&#8216;voornaam : &#8216;);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 readln(naw.voornaam);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 write(&#8216;adres: &#8216;);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 readln(naw.adres);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 write(&#8216;postcode: &#8216;);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 readln(naw.postcode);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 write(&#8216;plaats: &#8216;);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 readln(naw.plaats);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 write(&#8216;leeftijd: &#8216;);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 readln(naw.leeftijd);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 write(&#8216;geslacht (M\/V): &#8216;);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 repeat<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 read(kbd,w);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 until w in [&#8216;m&#8217;,&#8217;M&#8217;,&#8217;v&#8217;,&#8217;V&#8217;];<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 writeln(w);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 naw.geslacht := w;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 naw.naamcombi[1] := naw.voorletters + naw.achternaam;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 naw.naamcombi[2] := naw.voornaam + naw.achternaam;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">end;<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">procedure\u00a0ToonNAW(naw:\u00a0TNAW);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">begin<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 with naw do<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 begin<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 writeln(&#8216;achternaam: &#8216;,achternaam);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 writeln(&#8216;voorletters:\u00a0&#8216;,voorletters);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 writeln(&#8216;voornaam:\u00a0&#8216;,voornaam);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 writeln(&#8216;adres:\u00a0&#8216;,adres);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 writeln(&#8216;postcode:\u00a0&#8216;,postcode);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 writeln(&#8216;plaats:\u00a0&#8216;,plaats);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 writeln(&#8216;leeftijd:\u00a0&#8216;,leeftijd);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 write(&#8216;geslacht:\u00a0&#8216;);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 if\u00a0(geslacht=&#8217;m&#8217;)\u00a0or\u00a0(geslacht=&#8217;M&#8217;) then<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 \u00a0 writeln(&#8216;Man&#8217;)<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 else<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 \u00a0 writeln(&#8216;Vrouw&#8217;);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 writeln(&#8216;combi\u00a01:\u00a0&#8216;,naamcombi[1]);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 writeln(&#8216;combi\u00a02:\u00a0&#8216;,naamcombi[2]);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 end;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">end;<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">begin<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 LeesNAWIn(NAW);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 writeln;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 writeln;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 ToonNAW(NAW);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">end.<\/span><\/p>\n<p>Bij de type-declaratie is record-type\u00a0<b>TNAW<\/b>\u00a0gemaakt, waarin bepaalde waardes behorend bij een persoon logischerwijs bij elkaar zijn gezet.<br \/>\nLet even op het type van\u00a0<i>naamcombi<\/i>, dit is een array.<br \/>\nVervolgens maken we een variabele\u00a0<b>NAW<\/b>, waarin de gegevens daadwerkelijk kunnen worden opgeslagen.<br \/>\nOm bij een specifiek veld van NAW te komen, gebruiken we de punt-selector. Dus met\u00a0<b>NAW.achternaam<\/b>\u00a0bereik je het veld\u00a0<i>achternaam<\/i>.<br \/>\nBij de procedure\u00a0<b>LeesNAWIn<\/b>\u00a0wordt hiervan bij de\u00a0<i>read<\/i>&#8217;s gebruik gemaakt.<br \/>\nBij de procedure\u00a0<b>ToonNAW<\/b>\u00a0maken we gebruik van de\u00a0<b>with<\/b>-constructie. Hiermee onderdrukken we het gebruik van de punt-selector.<br \/>\nDe syntax luidt:<\/p>\n<p><b>with [variabele] do [opdracht];<br \/>\n<\/b><br \/>\nHierbij is\u00a0<i>[variabele]<\/i>\u00a0de naam van de variabele en\u00a0<i>[opdracht]<\/i>\u00a0de opdracht waarmee je iets met de\u00a0<i>[variabele]<\/i>\u00a0kunt doen. Ook hier mag\u00a0<i>[opdracht]<\/i>\u00a0een samengestelde opdracht zijn.<\/p>\n<p>Het zou natuurlijk prettiger zijn als we de gegevens van meer dan \u00e9\u00e9n persoon zouden kunnen verwerken.<br \/>\nEn dat is dan ook de volgende uitbreiding van het programma.<\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">program\u00a0P12_4;<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">const<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Max = 2;<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">type<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 s80 = string[80];<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 s40 = string[40];<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 s20 = string[20];<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 s15 = string[15];<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 s7 = string[7];<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 TNAW =<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 record<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 achternaam:\u00a0s40;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 voorletters:\u00a0s15;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 voornaam:\u00a0s20;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 adres:\u00a0s40;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 postcode:\u00a0s7;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 plaats:\u00a0s20;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 leeftijd:\u00a0byte;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 geslacht:\u00a0char;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 naamcombi:\u00a0array[1..2]\u00a0of\u00a0s80;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 end;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">TNAWs\u00a0=\u00a0array[1..Max]\u00a0of\u00a0TNAW;<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">var<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 NAW: TNAWs;<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">procedure\u00a0DrukToets;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 var c: char;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">begin<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 write(&#8216;Druk op een toets&#8230;&#8217;);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 read(kbd,c);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 writeln;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">end;<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">procedure\u00a0LeesNAWIn(var\u00a0naw:\u00a0TNAW);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 {dezelfde implementatie als in P12_3}<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">procedure\u00a0ToonNAW(naw:\u00a0TNAW);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 {dezelfde implementatie als in P12_3}<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">procedure\u00a0LeesNAWsIn;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 var x: byte;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">begin<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 for x := 1 to Max do<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 begin<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 writeln(&#8216;Voer\u00a0de\u00a0&#8216;,x,&#8217;-e\u00a0persoon in:&#8217;);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 writeln;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 LeesNAWIn(NAW[x]);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 writeln;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 end;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">end;<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">procedure\u00a0ToonNAWs;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 var x: byte;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">begin<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 for x := 1 to Max do<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 begin<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 writeln(&#8216;Gegevens\u00a0van\u00a0&#8216;,x,&#8217;-e persoon:&#8217;);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 writeln;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 ToonNAW(NAW[x]);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 writeln;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 DrukToets;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 writeln;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 end;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">end;<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">begin<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 LeesNAWsIn;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 writeln;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 writeln;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 ToonNAWs;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">end.<\/span><\/p>\n<p>Bij de type-declaraties is\u00a0<b>TNAWs<\/b>\u00a0toegevoegd als array van\u00a0<b>TNAW<\/b>. Het aantal NAW&#8217;s hangt af van de\u00a0<b>const<\/b>ante\u00a0<b>Max<\/b>.<br \/>\nDe variabele\u00a0<b>NAW<\/b>\u00a0is nu van het type\u00a0<b>TNAWs<\/b>.<br \/>\nDe procedure\u00a0<b>LeesNAWsIn<\/b>\u00a0leest nu\u00a0<i>Max<\/i>\u00a0NAW&#8217;s in.<br \/>\nDe procedure\u00a0<b>ToonNAWs<\/b>\u00a0laat de\u00a0<i>Max<\/i>\u00a0NAW&#8217;s per NAW zien, daartoe gebruik makend van de procedure\u00a0<b>DrukToets<\/b>.<\/p>\n<p>Tot slot willen we de ingevoerde gegevens natuurlijk op schijf kunnen bewaren.<br \/>\nZoals in hoofdstuk 10 reeds vermeld kunnen we dat doen d.m.v. een binair bestand dat gekoppeld is aan een type.<\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">program\u00a0P12_5;<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">const<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 Max = 2;<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">type<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 s80 = string[80];<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 s40 = string[40];<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 s20 = string[20];<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 s15 = string[15];<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 s7 = string[7];<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 TNAW =<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 record<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 achternaam:\u00a0s40;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 voorletters:\u00a0s15;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 voornaam:\u00a0s20;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 adres:\u00a0s40;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 postcode:\u00a0s7;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 plaats:\u00a0s20;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 leeftijd:\u00a0byte;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 geslacht:\u00a0char;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 naamcombi:\u00a0array[1..2]\u00a0of\u00a0s80;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 end;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">TNAWs\u00a0=\u00a0array[1..Max]\u00a0of\u00a0TNAW;<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">var<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 NAW: TNAWs;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 bNAW: file of TNAW;<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">function\u00a0Bestaat(bn:\u00a0s80):\u00a0Boolean;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 var b: file;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">begin<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 assign(b,bn);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 {$I-}<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 reset(b);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 {$I+}<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 if IOResult = 0 then<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 begin<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 close(b);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 Bestaat := true;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 end<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 else<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 Bestaat := false;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">end;<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">procedure\u00a0DrukToets;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 {dezelfde implementatie als in P12_4}<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">procedure\u00a0LeesNAWIn(var\u00a0naw:\u00a0TNAW);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 {dezelfde implementatie als in P12_3}<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">procedure\u00a0ToonNAW(naw:\u00a0TNAW);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 {dezelfde implementatie als in P12_3}<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">procedure\u00a0LeesNAWsIn;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 {dezelfde implementatie als in P12_4}<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">procedure\u00a0ToonNAWs;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 {dezelfde implementatie als in P12_4}<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">procedure\u00a0NAWsNaarSchijf;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 var x: byte;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">begin<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 assign(bNAW,&#8217;NAWS.GSP&#8217;);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 rewrite(bNAW);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 for x := 1 to Max do<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 write(bNAW,NAW[x]);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 close(bNAW);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">end;<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">procedure\u00a0NAWsVanSchijf;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 var x: byte;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">begin<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 assign(bNAW,&#8217;NAWS.GSP&#8217;);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 reset(bNAW);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 for x := 1 to Max do<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 read(bNAW,NAW[x]);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 close(bNAW);<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">end;<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">begin<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 if Bestaat(&#8216;NAWS.GSP&#8217;) then<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 begin<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 NAWsVanSchijf;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 ToonNAWs;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 end<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 else<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 begin<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 LeesNAWsIn;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 writeln;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 writeln;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 ToonNAWs;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 \u00a0 NAWsNaarSchijf;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">\u00a0 \u00a0 end;<\/span><br \/>\n<span style=\"font-family: 'courier new', courier, monospace; font-size: 12pt;\">end.<\/span><\/p>\n<p>Bij de variabele-declaratie is een variabele\u00a0<b>bNAW: file of TNAW<\/b>\u00a0gedeclareerd. Met deze variabele kunnen we een bestand maken of lezen die als inhoud NAW-reocrds heeft. Deze records worden binair opgelagen.<br \/>\nDe functie\u00a0<b>Bestaat<\/b>\u00a0is al in hoofdstuk 10 besproken.<br \/>\nDe procedure\u00a0<b>NAWsNaarSchijf<\/b>\u00a0zet de NAW-records op schijf. Hierbij wordt het\u00a0<b>write<\/b>-statement gebruikt en niet\u00a0<b>writeln<\/b>.<br \/>\nDe procedure\u00a0<b>NAWsVanSchijf<\/b>\u00a0leest de NAW-records van schijf. Hierbij wordt het\u00a0<b>read<\/b>-statement gebruikt en niet\u00a0<b>readln<\/b>.<\/p>\n<p>Tot zover dit uitgebreide hoofdstuk.<br \/>\nTot zover ook de basis van het programmeren.<br \/>\nDe eventuele verdere hoofdstukken behandelen andere gevorderde programmeer-zaken.<\/p>\n<h2>Oefeningen.<\/h2>\n<p><a name=\"12.1\"><\/a><b>12.1<\/b><br \/>\nSchrijf een programma dat twee matrices (maximale dimensie 10) vermenigvuldigd.<br \/>\nDe gebruiker moet eerst de dimensies van de 1e matrix ingeven. Hierna moeten de twee matrices worden ingelezen.<br \/>\nTen slotte moet de resultaat-matrix worden getoond.<br \/>\nDe matrix vermenigvuldiging gaat als volgt:<br \/>\nHet element (x,y) van de resultaat matrix is de som van de producten van de oplopende elementen van de x-e rij van de eerste matrix met de oplopende elementen van de y-e kolom van de tweede matrix.<br \/>\nDat betekend dat wanneer de eerste matrix de dimensie axb heeft de tweede als dimensie bxa moet hebben.<br \/>\nVerder zal de resultaat-matrix een vierkante dimensie hebben van axa als a groter is dan b, anders bxb.<br \/>\nVoorbeeldje:<\/p>\n<p><span style=\"font-family: courier new; font-size: small;\"><b>|1|\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0|3 4|<br \/>\n| | x (3 4) = |\u00a0\u00a0\u00a0|<br \/>\n|2|\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0|6 8|<br \/>\n<\/b><\/span><\/p>\n<p> [<a href=\"https:\/\/wiskunst.nl\/index.php\/programmeren\/oefeningen\/#12.1\" target=\"_blank\" rel=\"noopener\">Antwoord<\/a>]\n<p><a name=\"12.2\"><\/a><b>12.2<\/b><br \/>\nSchrijf een programma dat een datum als string inleest en deze middels een procedure omzet naar een variabele van het type\u00a0<b>TDatum<\/b>.<br \/>\nUiteraard moet de procedure testen of de string wel een datum is! Zo niet dan worden alle velden (zie volgende regel) op 0 gezet.<br \/>\nHet type\u00a0<b>TDatum<\/b>\u00a0is een, zelf te maken, record-type met de volgende integer-velden:\u00a0<i>jaar<\/i>,\u00a0<i>maand<\/i>\u00a0en\u00a0<i>dag<\/i>.<br \/>\nVervolgens moeten er drie functies bestaan die uit een TDatum-variabele resp. het\u00a0<b>Jaar<\/b>,\u00a0<b>Maand<\/b>\u00a0en\u00a0<b>Dag<\/b>\u00a0als integer moeten halen.<br \/>\nTest alles door de invoer middels de functies als uitvoer te geven. [<a href=\"https:\/\/wiskunst.nl\/index.php\/programmeren\/oefeningen\/#12.2\" target=\"_blank\" rel=\"noopener\">Antwoord<\/a>]\n<p><a name=\"12.3\"><\/a><b>12.3<\/b><br \/>\nDe meest complexe tot nog toe, maar laat je daardoor niet van de wijs brengen. Met alle kennis die je tot nog toe hebt opgedaan en met nog enkele tips kom je er wel uit.<br \/>\nDeze oefening luidt: Schrijf een programma dat de volgende handelingen met breuken kan uitvoeren:<br \/>\n&#8211; twee breuken optellen<br \/>\n&#8211; twee breuken aftrekken<br \/>\n&#8211; twee breuken vermenigvuldigen<br \/>\n&#8211; twee breuken delen<br \/>\n&#8211; een breuk vereenvoudigen<br \/>\n&#8211; een breuk decimaal kan maken.<\/p>\n<p>Tevens moet het programma in staat zijn om optioneel de resultaten in een bestand op schijf te bewaren.<\/p>\n<p>E\u00e9n en ander moet in een menu aan de gebruiker worden aangeboden.<\/p>\n<p>Tips:<br \/>\nGebruik een record-type TBreuk om een breuk te representeren.<br \/>\nOm breuken te vereenvoudigen is het handig om de ggd van teller en noemer te bepalen, schrijf daartoe een functie Ggd.<br \/>\nHierbij kun je gebruik maken van het algoritme van Euclides:<br \/>\n1. Bepaal de gehele deling (div) en rest (mod) van teller en noemer,<br \/>\n2. Als de rest 0 is, dan is de ggd=noemer,<br \/>\n3. Anders is de ggd= ggd van de noemer en de rest (dus recursief).<br \/>\nOm een breuk in te lezen maak je gebruik van een procedure die teller en noemer apart vraagt.<br \/>\nOm een breuk op het scherm (of in het bestand) te schrijven maak je gebruik van een functie.<br \/>\nDaarbij is het handig om een functie IntToStr te hebben die een integer omzet naar een string.<br \/>\nMaak die functie en maak daarbij gebruik van de ingebouwde functie chr([waarde]), die [waarde] omzet naar een char met ascii-waarde [waarde] (&#8216;0&#8217;=48, &#8216;9&#8217;=57). [<a href=\"https:\/\/wiskunst.nl\/index.php\/programmeren\/oefeningen\/#12.3\" target=\"_blank\" rel=\"noopener\">Antwoord<\/a>]\n<p> [<a href=\"https:\/\/wiskunst.nl\/index.php\/programmeren\/recursie\/\">Recursie<\/a>] &lt;&#8211; &#8211;&gt; [<a href=\"https:\/\/wiskunst.nl\/index.php\/programmeren\/pointers\/\">Pointers<\/a>]\n","protected":false},"excerpt":{"rendered":"<p>We hebben al een aantal keer (gedwongen) gebruik gemaakt van een type-declaratie voor strings. Pascal kent het principe van zelfgemaakte types. In hoofdstuk 8 (of 9) hebben we hier een paar voorbeelden van gezien. In dit hoofdstuk gaan we ons bezig houden met gestructureerde types. Deze versie van Pascal kent twee gestructureerde types, nl. de\u00a0array\u00a0en [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":185,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"templates\/template-full-width.php","meta":{"_lmt_disableupdate":"","_lmt_disable":"","footnotes":""},"class_list":["post-210","page","type-page","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Gestructureerde types - Wiskunst<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/wiskunst.nl\/index.php\/programmeren1\/programmeren\/gestructureerde-types\/\" \/>\n<meta property=\"og:locale\" content=\"nl_NL\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Gestructureerde types - Wiskunst\" \/>\n<meta property=\"og:description\" content=\"We hebben al een aantal keer (gedwongen) gebruik gemaakt van een type-declaratie voor strings. Pascal kent het principe van zelfgemaakte types. In hoofdstuk 8 (of 9) hebben we hier een paar voorbeelden van gezien. In dit hoofdstuk gaan we ons bezig houden met gestructureerde types. Deze versie van Pascal kent twee gestructureerde types, nl. de\u00a0array\u00a0en [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/wiskunst.nl\/index.php\/programmeren1\/programmeren\/gestructureerde-types\/\" \/>\n<meta property=\"og:site_name\" content=\"Wiskunst\" \/>\n<meta property=\"article:modified_time\" content=\"2022-01-24T08:36:55+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Geschatte leestijd\" \/>\n\t<meta name=\"twitter:data1\" content=\"10 minuten\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/wiskunst.nl\\\/index.php\\\/programmeren1\\\/programmeren\\\/gestructureerde-types\\\/\",\"url\":\"https:\\\/\\\/wiskunst.nl\\\/index.php\\\/programmeren1\\\/programmeren\\\/gestructureerde-types\\\/\",\"name\":\"Gestructureerde types - Wiskunst\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/wiskunst.nl\\\/#website\"},\"datePublished\":\"2022-01-20T14:55:25+00:00\",\"dateModified\":\"2022-01-24T08:36:55+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/wiskunst.nl\\\/index.php\\\/programmeren1\\\/programmeren\\\/gestructureerde-types\\\/#breadcrumb\"},\"inLanguage\":\"nl-NL\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/wiskunst.nl\\\/index.php\\\/programmeren1\\\/programmeren\\\/gestructureerde-types\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/wiskunst.nl\\\/index.php\\\/programmeren1\\\/programmeren\\\/gestructureerde-types\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/wiskunst.nl\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Programmeren\",\"item\":\"https:\\\/\\\/wiskunst.nl\\\/index.php\\\/programmeren1\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Programmeren met Pascal\",\"item\":\"https:\\\/\\\/wiskunst.nl\\\/index.php\\\/programmeren1\\\/programmeren\\\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Gestructureerde types\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/wiskunst.nl\\\/#website\",\"url\":\"https:\\\/\\\/wiskunst.nl\\\/\",\"name\":\"Wiskunst\",\"description\":\"2\u221e\u2227&gt;\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/wiskunst.nl\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"nl-NL\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Gestructureerde types - Wiskunst","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/wiskunst.nl\/index.php\/programmeren1\/programmeren\/gestructureerde-types\/","og_locale":"nl_NL","og_type":"article","og_title":"Gestructureerde types - Wiskunst","og_description":"We hebben al een aantal keer (gedwongen) gebruik gemaakt van een type-declaratie voor strings. Pascal kent het principe van zelfgemaakte types. In hoofdstuk 8 (of 9) hebben we hier een paar voorbeelden van gezien. In dit hoofdstuk gaan we ons bezig houden met gestructureerde types. Deze versie van Pascal kent twee gestructureerde types, nl. de\u00a0array\u00a0en [&hellip;]","og_url":"https:\/\/wiskunst.nl\/index.php\/programmeren1\/programmeren\/gestructureerde-types\/","og_site_name":"Wiskunst","article_modified_time":"2022-01-24T08:36:55+00:00","twitter_card":"summary_large_image","twitter_misc":{"Geschatte leestijd":"10 minuten"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/wiskunst.nl\/index.php\/programmeren1\/programmeren\/gestructureerde-types\/","url":"https:\/\/wiskunst.nl\/index.php\/programmeren1\/programmeren\/gestructureerde-types\/","name":"Gestructureerde types - Wiskunst","isPartOf":{"@id":"https:\/\/wiskunst.nl\/#website"},"datePublished":"2022-01-20T14:55:25+00:00","dateModified":"2022-01-24T08:36:55+00:00","breadcrumb":{"@id":"https:\/\/wiskunst.nl\/index.php\/programmeren1\/programmeren\/gestructureerde-types\/#breadcrumb"},"inLanguage":"nl-NL","potentialAction":[{"@type":"ReadAction","target":["https:\/\/wiskunst.nl\/index.php\/programmeren1\/programmeren\/gestructureerde-types\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/wiskunst.nl\/index.php\/programmeren1\/programmeren\/gestructureerde-types\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/wiskunst.nl\/"},{"@type":"ListItem","position":2,"name":"Programmeren","item":"https:\/\/wiskunst.nl\/index.php\/programmeren1\/"},{"@type":"ListItem","position":3,"name":"Programmeren met Pascal","item":"https:\/\/wiskunst.nl\/index.php\/programmeren1\/programmeren\/"},{"@type":"ListItem","position":4,"name":"Gestructureerde types"}]},{"@type":"WebSite","@id":"https:\/\/wiskunst.nl\/#website","url":"https:\/\/wiskunst.nl\/","name":"Wiskunst","description":"2\u221e\u2227&gt;","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/wiskunst.nl\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"nl-NL"}]}},"_links":{"self":[{"href":"https:\/\/wiskunst.nl\/index.php\/wp-json\/wp\/v2\/pages\/210","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wiskunst.nl\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/wiskunst.nl\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/wiskunst.nl\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wiskunst.nl\/index.php\/wp-json\/wp\/v2\/comments?post=210"}],"version-history":[{"count":7,"href":"https:\/\/wiskunst.nl\/index.php\/wp-json\/wp\/v2\/pages\/210\/revisions"}],"predecessor-version":[{"id":541,"href":"https:\/\/wiskunst.nl\/index.php\/wp-json\/wp\/v2\/pages\/210\/revisions\/541"}],"up":[{"embeddable":true,"href":"https:\/\/wiskunst.nl\/index.php\/wp-json\/wp\/v2\/pages\/185"}],"wp:attachment":[{"href":"https:\/\/wiskunst.nl\/index.php\/wp-json\/wp\/v2\/media?parent=210"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}