Pascal: Add Examination Scores

program pupil_exams;
const max = 5;
type exam_record = record
          name : string;
          form : string;
          mark1, mark2, total : integer;
          grade: char;
        end;
        exam_array = array [1..max] of exam_record;

var  scores : exam_array;
        n, result : integer;
        x : char;

procedure get_data;
var i : integer;
begin
  writeln ('Enter details of ', max, ' pupils, name, form and scores for two exams');
  for i:= 1 to max do 
    begin
      writeln ('Enter name:');
      readln (scores[i].name);
      writeln ('Enter form:');
      readln (scores[i].form);
      writeln ('Enter score for paper 1:');
      readln (scores[i].mark1);
      writeln ('Enter score for paper 2:');
      readln (scores[i].mark2);
      scores[i].total := scores[i].mark1 + scores[i].mark2;
      if scores[i].total < 50 then scores[i].grade := 'F'
      else
        if scores[i].total >=70 then scores[i].grade := 'A'
        else
           if scores[i].total >=60 then scores[i].grade := 'B'
           else
             if scores[i].total >=50 then scores[i].grade := 'C';
    end;
end;

procedure show_data;
var i : integer;
begin
  writeln ('Results are:');
  for i:= 1 to max do
    begin
      writeln ('Name: ', scores[i].name);
      writeln ('Form: ', scores[i].form);
      writeln ('Total mark: ', scores[i].total);
      writeln ('Grade: ', scores[i].grade);
    end;
end;

procedure sort_data;
var i, j: integer;
      temp : exam_record;
begin
  for i := 1 to max -1 do
    for j := i + 1 to max do
      if
scores[i].total > scores[j].total then 
        begin
          temp :=
scores[i];
         
scores[i] := scores[j];
         
scores[j] := temp;
        end;
end;

begin
  get_data;
  sort_data;
  show_data;
  readln (x);
end.

 

Back to questions