Computer Science Canada

finding highest and lowest marks out of the inputed marks

Author:  new [ Tue Dec 21, 2004 4:07 am ]
Post subject:  finding highest and lowest marks out of the inputed marks

this programs gets imput (teacher name, sudent name and thier marks then save it, then finds highest and lowest)

Author:  Cervantes [ Tue Dec 21, 2004 7:30 am ]
Post subject: 

Not bad, but you should do some error trapping to make sure the input (for the marks) is between 0 and 100.
Also, there's really now need to make a procedure with no parameters called into and then call it immediately after making the procedure. If you want to title that group of code as the introduction, just use comments Wink

Author:  Artimes [ Tue Dec 21, 2004 11:28 pm ]
Post subject: 

Pritty good, simple I may add though. You should've make it sorted itself, then shown them all.

code:

for decreasing i : (arraySize - 1) .. 1
    for j : (arraySize - 1) .. 19
        if (markStudent (j) > markStudent (j + 1)) then
           
            % Change variable to choose what you sort by
            % > Sort from greatest to least
            % < Sort from least to greatest
           
            intTemp := markStudent (j)
            markStudent (j) := markStudent (j + 1)
            markStudent (j + 1) := intTemp

            stringTemp := nameStudent (j)
            nameStudent (j) := nameStudent (j + 1)
            nameStudent (j + 1) := stringTemp
           
            % The more parametres you have (i.e. name, mark, class)
            % You to repeat these three lines of code
        end if
    end for
end for


Author:  Cervantes [ Wed Dec 22, 2004 8:16 am ]
Post subject: 

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

Author:  Artimes [ Wed Dec 22, 2004 10:27 am ]
Post subject: 

You learn somthing new every day Razz


: