Multiple-choice questions analysis

Delphi & Pascal (česká wiki)
Přejít na: navigace, hledání
Kategorija: Zadaňa zos Pascalu

Program: Mc_school.pas
Subor exe: Mc_school.exe
Ukažka: Input.txtAnswer.txt

Multiple-choice questions analysis.
This program is use to read all text-based data and produce a analysis report on the competition.
The analysis report include:
  • total number of participants ,total number of participating schools and total number of participant from each participating school
  • the participant of the highest marks and the highest marks school
  • question analysis such as the percentage correct for each question
{ MC_SCHOOL.PAS             Copyright (c) TrSek alias Zdeno Sekerak }
{ Multiple-Choise Analysis Report                                   }
{                                                                   }
{ Na medziskolskej matematickej sutazi, formov testou otazok bola   }
{ zorganizovana sutaz. Odpovedne harky pre ucastnikov boli citane   }
{ pomocou Optickeho spracovania vysledkov (OMR) a volby boli        }
{ konvertovane do textoveho suboru.                                 }
{                                                                   }
{ Predstavte si ze ste programator. Idete vyvyjat pocitacovy        }
{ program na citanie vsetkých suborovych textovych dat a produkovat }
{ detailne analyzy zo skusok.                                       }
{                                                                   }
{ Analyzy budu obsahovat.                                           }
{ - celkovy pocet ucastnikov, celkovy pocet skol,                   }
{   celkovy pocet ucastnikov z kazdej skoly                         }
{ - vitaza jednotlivych cien a vitaza za skolu                      }
{ - otazky zanalyzujte s percentualnym vyjadrenim                   }
{ - zobrazte jasny vysledok                                         }
{                                                                   }
{ Author: Zdeno Sekerak                                             }
{ Date  : 29.07.2008                           http://www.trsek.com }
 
program mc;
const MAX=50;
type
  pperson = record
	name : string[14];
	ans  : string[40];
	mark : integer;
	sch  : string[20];
  end;
 
  pschool = record
	name : string[14];
	count: integer;
  end;
 
var
  fn, fa: string;
  count : integer;
  count_sch : integer;
  count_ans : integer;
  i, fi : integer;
  answer: string;
  person: array[1..MAX] of pperson;
  school: array[1..MAX] of pschool;
  anmark: array[1..40] of real;
 
 
{ read txt file }
procedure read_file_mc( name: string );
var   f: text;
	  s: string;
  is,ie: integer; {start, end}
     ic: integer;
 
begin
  assign(f, name);
  reset(f);
  count:=0;
 
  While not eof(f) do
    begin
      count:= count + 1;
      readln(f, s);
 
      { now find first char answer }
      is:=14;
      while((s[is] = ' ') and (is<length(s))) do is:=is+1;
 
      { last char answer }
      ie:=is;
      while((s[ie]<> ' ') and (ie<length(s))) do ie:=ie+1;
      { first char of school }
      ic:=ie;
      while((s[ic] = ' ') and (ic<length(s))) do ic:=ic+1;
 
      person[count].name := copy(s, 1, 14);
      person[count].ans  := copy(s, is, ie-is);
      person[count].sch  := copy(s, ic, length(s)-ic+1);
 
      { trim name }
      while( person[count].name[ length(person[count].name)] = ' ') do
        delete(person[count].name, length(person[count].name), 1);
 
      { trim school }
      while( person[count].sch[ length(person[count].sch)] = ' ') do
        delete(person[count].sch, length(person[count].sch), 1);
    end;
 
    close(f);
end;
 
 
{ read answer }
procedure read_file_ans( name: string );
var   f: text;
	  s: string;
begin
  assign(f, name);
  reset(f);
  readln(f, answer);
  close(f);
end;
 
 
{ correct answer per person }
procedure correct_answer;
var i,y:integer;
begin
  for i:=1 to count do
  begin
	person[i].mark:=0;
 
	for y:=1 to length(answer) do
	begin
	  { correct answer }
	  if( y<=length(person[i].ans))then
	  if( UpCase(answer[y]) = UpCase(person[i].ans[y])) then
          person[i].mark:=person[i].mark+1;
	end;
 
  end;
end;
 
 
{ sort person per mark }
procedure sort_answer_mark;
var     i: integer;
   is_end: boolean;
      pom: pperson;
begin
  repeat
    is_end:=true;
    for i:=1 to count-1 do
      if person[i].mark < person[i+1].mark then
        begin
		  { switch person }
		  pom := person[i];
		  person[i]:=person[i+1];
		  person[i+1]:=pom;
 
		  { finish indikator }
          is_end:=false;
        end;
  until (is_end);
end;
 
 
{ count per school }
procedure count_per_school;
var i,y:integer;
begin
  count_sch:=0;
 
  for i:=1 to count do
  begin
	{ find it }
	y:=1;
	while((y<=count_sch) and (school[y].name <> person[i].sch)) do
	  y:=y+1;
 
	{ no found }
	if( count_sch < y )then
	begin
		count_sch:=count_sch+1;
		school[y].name := person[i].sch
	end;
 
	{ count it }
	school[y].count := school[y].count+1;
  end;
end;
 
 
{ find the first person of school }
function find_school(sch:string): integer;
var i:integer;
begin
  find_school:=1;
  for i:=1 to count do
    if( person[i].sch = sch )then begin
        find_school:=i;
        break;
	end;
end;
 
 
{ percent answer }
procedure answer_percent;
var i,y:integer;
begin
	count_ans := length(answer);
 
	for i:=1 to count_ans do
	begin
      anmark[i]:=0;
 
	  for y:=1 to count do
	    if( upcase(person[y].ans[i]) = upcase(answer[i]))then
            anmark[i]:=anmark[i]+1;
 
	  anmark[i]:= 100*(anmark[i]/count);
	end;
end;
 
 
begin
  writeln('File name:');
  {fn:='input.txt';}
  readln(fn);
  read_file_mc(fn);
 
  writeln('File answer:');
  {fa:='answer.txt';}
  readln(fa);
  read_file_ans(fa);
 
  writeln('wait I counting');
  correct_answer;
  sort_answer_mark;
  count_per_school;
  answer_percent;
 
  { answer }
  for i:=1 to 25 do writeln;
  writeln('Total person is ', count);
  writeln('Total school is ', count_sch);
  writeln('School');
  for i:=1 to count_sch do
	writeln(i:2,'  ', school[i].name:10,'  person = ',school[i].count);
 
  writeln;
  writeln('The highest is ', person[1].mark);
  writeln('He/She is      ', person[1].name);
  writeln('He/She is in   ', person[1].sch, ' Secondary School.');
 
  writeln;
  writeln('The highest per school');
  for i:=1 to count_sch do
  begin
     fi := find_school( school[i].name );
     writeln(person[fi].sch, ' Secondary School.');
     writeln('The highest is ', person[fi].mark);
     writeln('He/She is      ', person[fi].name);
     writeln;
  end;
 
  writeln('Percentual answer');
  for i:=1 to count_ans do
	writeln(i:2, ' ', anmark[i]:4:1, '%  correct = ', answer[i]);
 
  readln;
end.