0

30 問 (15 問の多肢選択式) の簡単なクイズ プログラムを作成し、すべての質問の順序をランダム化しようとしています。また、結果をパーセントで計算し、不正解の質問を正しい回答とともに表示する必要があります。例の質問が 3 つまたは 4 つあるサンプルだけでも問題ありません。

同じ質問が複数回表示されるのは望ましくありません。これをうまく行う方法を学ぶためにダウンロードできる無料のソースコードはありますか? 私はただの初心者であり、実際に使用される戦術を学び、見たいと思っています.

テキストファイルから質問を読み取っていますが、ユーザー名と以前のユーザーのスコアを表示するように変更したいと思います。プログラムを変更するか、ソースコードを持っている人がいれば私が感謝する簡単なクイズプログラム。

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs,Unit2, StdCtrls, Grids;

type
  TForm1 = class(TForm)
    Button1: TButton;
    StringGrid1: TStringGrid;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;


implementation

{$R *.dfm}

var
namefile, tmp : string;
f: text;
l,i,j,c: integer;
cc: double;
mas: array [1..100] of integer;

procedure TForm1.Button1Click(Sender: TObject);
begin
  reset(f);
  readln(f,l);
  for I := 1 to l do
  begin
    Form2.Label1.Caption := 'Вопрос № '+Inttostr(i+1);
     readln(f,tmp);
     Form2.Label2.Caption := tmp;
     readln(f,tmp);
     Form2.RadioButton1.Caption := tmp;
     readln(f,tmp);
     Form2.RadioButton2.Caption :=tmp;
     readln(f,tmp);
     Form2.RadioButton3.Caption :=tmp;
     readln(f,tmp);
     Form2.RadioButton4.Caption :=tmp;
     readln(f,j);

     Form2.ShowModal;

     if (Form2.RadioButton1.Checked) then
           if (j=1) then
              mas[i]:=1;
     if (Form2.RadioButton2.Checked) then
           if (j=2) then
              mas[i]:=1;
     if (Form2.RadioButton3.Checked) then
           if (j=3) then
              mas[i]:=1;
     if (Form2.RadioButton4.Checked) then
           if (j=4) then
              mas[i]:=1;
  end;
  c:=0;
  for I := 1 to l do
    if mas[i]=1 then
      c:=c+1;
  cc:=(c*100)/l;

  label3.Caption:= 'Правильных ответов '+FloatToStr(cc)+'%';

  for I := 0 to l-1 do
     stringgrid1.Cells[i,1]:=IntToStr(mas[i+1]);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  namefile:='test.txt';
  AssignFile(f, namefile);
  reset(f);
  readln(f,l);
  stringgrid1.ColCount:=l;
  for I := 1 to l do
    mas[i]:=0;
  for I := 0 to l-1 do
     stringgrid1.Cells[i,0]:=IntToStr(i+1);
  for I := 0 to l-1 do
    stringgrid1.Cells[i,1]:=IntToStr(mas[i+1]);
end;

end.
4

1 に答える 1

0

部分的な回答:
ユーザー スコアを維持したい場合、このレベルで進歩するための最善の策は、ユーザー名とスコアを維持するための 2 つ目のテキスト ファイルを作成することです。
それらを配列に読み込みます。プログラムの開始時にユーザー名を尋ね、クイズを実行し、すでにそのユーザーを知っているかどうかを確認し、配列を更新して、書き戻します。

次のステップは、データベースへのアクセスを学び、すべてのデータをテキスト ファイルではなくデータベースに保存することです。

これで今のところ十分な運動ができるはずです;-)

トゥーンが言ったように、ここで具体的な質問をしてください。

また、機能するプログラムを作成したら、https://codereview.stackexchange.com/にアップして改善を求めることもできます。
StackOverflow はそのための場所ではありません。

于 2013-05-07T20:02:23.927 に答える