home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / CPM / EDUCATIN / FRENCH.LBR / FRENCH1.PZS / FRENCH1.PAS
Pascal/Delphi Source File  |  2000-06-30  |  6KB  |  200 lines

  1. (* French vocabulary test program *)
  2. (* by Jon Dart, 1866 Diamond St., San Diego, CA 92109 *)
  3. (* Version 1.9, 10-JUL-85 *)
  4.  
  5. const
  6.     maxquestions   = 50;     (* max. num of questions/quiz *)
  7.  
  8. type
  9.     quiztype       = (FRENCHTOENGLISH,ENGLISHTOFRENCH,GENDER);
  10.     repeatoption   = (SAMEWORDS,WRONGWORDS,NEWQUIZ,EXIT);
  11.     stringarray    = array[1..maxquestions] of textline;
  12.     integerarray   = array[1..maxquestions] of integer;
  13.     booleanarray   = array[1..maxquestions] of boolean;
  14.  
  15. var
  16.      nounfile, nonounfile     :filedesc;
  17.      numquizquestions         :integer;
  18.      numquestions             :integer;
  19.      numnouns,numnonouns      :integer;
  20.      numwrong                 :integer;
  21.      maxitems,k               :integer;
  22.      quizitems                :stringarray;
  23.      order                    :integerarray;
  24.      wrong                    :booleanarray;
  25.      quit                     :boolean;
  26.      quiz                     :quiztype;
  27.      option                   :repeatoption;
  28.  
  29. procedure openfiles(var nounfile,nonounfile:filedesc);
  30. var
  31.      name1,name2    :textline;
  32. begin
  33.      setstring(name1,'FRNOUN.DAT');
  34.      nounfile := open(name1,IOREAD);
  35.      if nounfile = IOERROR then
  36.           error('Can''t Open FRNOUN.DAT');
  37.      setstring(name2,'FRNONOUN.DAT');
  38.      nonounfile := open(name2,IOREAD);
  39.      if nonounfile = IOERROR then
  40.           error('Can''t Open FRNONOUN.DAT');
  41. end;
  42.  
  43. procedure readsizes(var numnouns,numnonouns: integer);
  44.  (* read the first lines of NOUN.DAT and NONOUN.DAT, which should contain
  45.     the num of lines in each file *)
  46.  
  47. var
  48.      s    :textline;
  49.      c    :character;
  50.      i    :integer;
  51. begin
  52.      if getline(s,nounfile,MAXSTR) then
  53.      begin
  54.           i:=1;
  55.           numnouns := ctoi(s,i);
  56.      end;
  57.      if getline(s,nonounfile,MAXSTR) then
  58.      begin
  59.           i := 1;
  60.           numnonouns := ctoi(s,i);
  61.      end;
  62. end;
  63.  
  64. procedure getquiztype(var quiz:quiztype);
  65.  
  66. var  c    :character;
  67.      junk :character;
  68.      j,k  :integer;
  69.  
  70. begin
  71.      writeln;
  72.      writeln('SELECT ONE:');
  73.      writeln;
  74.      writeln('1 - WORD QUIZ: FRENCH TO ENGLISH');
  75.      writeln('2 - WORD QUIZ: ENGLISH TO FRENCH');
  76.      writeln('3 - GENDER QUIZ (NOUNS ONLY)');
  77.      writeln;
  78.      repeat
  79.           write('? ');
  80.           junk := getc(c);
  81.           if not (c in [ord('1'),ord('2'),ord('3')]) then writeln;
  82.      until c in [ord('1'),ord('2'),ord('3')];
  83.      j := c-ord('1');
  84.      quiz := FRENCHTOENGLISH;
  85.      for k:=1 to j do quiz := succ(quiz);
  86.      writeln;
  87. end;
  88.  
  89. procedure getnumquestions(var quiz:quiztype; var numquestions,
  90.                                maxitems:integer);
  91.  
  92. var
  93.      ok        :boolean;
  94.      s         :textline;
  95.      i         :integer;
  96. begin
  97.      repeat
  98.           write('HOW MANY QUESTIONS (50 MAX.)? ');
  99.           if getline(s,TRMIN,MAXSTR) then
  100.           begin
  101.                i := 1;
  102.                numquestions := ctoi(s,i);
  103.           end;
  104.           if not numquestions in [0..50] then
  105.           begin
  106.                writeln('ERROR - MUST BE 0-50');
  107.                ok := false;
  108.           end
  109.           else if numquestions > maxitems then
  110.           begin
  111.                writeln('ONLY ',maxitems,' AVAILABLE.');
  112.                ok := false;
  113.           end
  114.           else ok:=true;
  115.      until ok;
  116. end (* getnumquestions *);
  117.  
  118. procedure ucline(var s:textline);
  119.  
  120. { makes line upper-case }
  121.  
  122. var
  123.      k   :integer;
  124. begin
  125.      k := 1;
  126.      while s[k] <> EOS do
  127.      begin
  128.           s[k] := toupper(s[k]);
  129.           k := k + 1;
  130.      end;
  131. end;
  132.  
  133. procedure fillarray(var quiz:quiztype;var quizitems:stringarray;
  134.                      numquestions,numnouns,numnonouns,
  135.                      maxitems :integer);
  136.  
  137. var
  138.      line            :textline;
  139.      t,k,numfilled   :integer;
  140.      endoffile       :boolean;
  141. begin
  142.      writeln;
  143.      writeln('READING DATA FILES');
  144.      numfilled := 0;
  145.      if quiz <> GENDER then
  146.      begin
  147.           t := (numquestions*numnonouns) div maxitems;
  148.           k := 0;  endoffile := false;
  149.           while (t > 0) and (k < numnonouns) and (not endoffile) do
  150.           begin
  151.                if getline(line,nonounfile,MAXSTR) then
  152.                begin
  153.                     k := k + 1;
  154.                     if random <= (t/(numnonouns - k + 1)) then
  155.                     begin
  156.                          numfilled := numfilled + 1;
  157.                          ucline(line);
  158.                          quizitems[numfilled] := line;
  159.                          write('.');
  160.                          t := t - 1;
  161.                     end;
  162.                end
  163.                else endoffile := true;
  164.           end;
  165.      end;
  166.      t := numquestions - numfilled;
  167.      k := 0;  endoffile := false;
  168.      while (t > 0) and (k < numnouns) and (not endoffile) do
  169.      begin
  170.           if getline(line,nounfile,MAXSTR) then
  171.           begin
  172.                k := k + 1;
  173.                if random <= (t/(numnouns - k + 1)) then
  174.                begin
  175.                     numfilled := numfilled + 1;
  176.                     ucline(line);
  177.                     quizitems[numfilled] := line;
  178.                     write('.');
  179.                     t := t - 1;
  180.                end;
  181.           end
  182.           else endoffile := true;
  183.      end;
  184.      writeln;
  185. end (* fillarray *);
  186.  
  187. procedure scramble(var order:integerarray; numquestions: integer);
  188.  
  189. var  k,k1,k2,temp  :integer;
  190.  
  191. begin
  192.      for k:=1 to numquestions*3 do
  193.      begin
  194.           k1 := random(numquestions) + 1;
  195.           k2 := random(numquestions) + 1;
  196.           temp := order[k1]; order[k1] := order[k2]; order[k2] := temp;
  197.      end;
  198. end;
  199.  
  200.