Artemis wrote:
% The more parametres you have (i.e. name, mark, class)
% You to repeat these three lines of code
Not necessarily. You can use records:
code: |
var howmany : int
put "How many students? " ..
get howmany
var student : array 1 .. howmany + 1 of %the +1 will be used as a temporary holder
record
mark : int
name : string
end record
for i : 1 .. howmany
student (i).mark := Rand.Int (0, 100)
student (i).name := chr (Rand.Int (65, 90)) %yes, their names are actually letters.
end for
for decreasing i : (howmany - 1) .. 1
for j : 1 .. (howmany - 1)
if (student (j).mark > student (j + 1).mark) then
% Change variable to choose what you sort by
% > Sort from greatest to least
% < Sort from least to greatest
%make the entire record equal to a different element of that record
student (howmany + 1) := student (j)
student (j) := student (j + 1)
student (j + 1) := student (howmany + 1)
end if
end for
end for
for i : 1 .. howmany
locate (i, 1)
put student (i).name
locate (i, 6)
put student (i).mark
end for
|