18.10.2014 Views

SIMSCRIPT II.5 Programming Language

SIMSCRIPT II.5 Programming Language

SIMSCRIPT II.5 Programming Language

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Advanced Topics<br />

one for each level of the genealogical tree. Assume that the number of levels in the tree and the<br />

names (coded as integer numbers) of the family members arranged in proper order on data records<br />

are given. A tree with the family data suitably arranged is first constructed using the following program:<br />

preamble<br />

normally mode is integer<br />

define LEVEL and TREE as 1-dimensional arrays<br />

end<br />

read N<br />

'' Number of levels<br />

reserve LEVEL(*) as N<br />

for I = 1 to N,<br />

do<br />

reserve TREE(*) as 2**(I-1)<br />

read TREE<br />

let LEVEL(I) = TREE(*)<br />

let TREE(*) = 0<br />

loop<br />

stop<br />

end<br />

For N = 4, the memory structure at the end of program execution looks as shown in figure 6-9. To<br />

print out a person's Kth-level ancestors, write:<br />

read K<br />

let TREE(*) = LEVEL(K)<br />

for I = 1 to 2**(K-1)<br />

print 1 line with TREE(I) as follows<br />

Ancestor is **<br />

To pick out specific ancestors, the tree can be searched until a matching code is found:<br />

read CODE<br />

for I = 1 to N,<br />

do<br />

let TREE(*) = LEVEL(I)<br />

for J = 1 to 2**(I-1)<br />

do<br />

if TREE(J) equals CODE<br />

print 1 line with CODE, J and I as follows<br />

Ancestor ** found in position * of level *<br />

stop<br />

otherwise<br />

loop<br />

loop<br />

print 1 line with CODE as follows<br />

UNABLE TO FIND AN ANCESTOR WITH THE CODE **<br />

stop<br />

end<br />

255

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!