Технический форум

Технический форум (http://www.tehnari.ru/)
-   Помощь студентам (http://www.tehnari.ru/f41/)
-   -   Дополнение программы (http://www.tehnari.ru/f41/t257019/)

Vera101 08.12.2017 23:56

Дополнение программы
 
Здравствуйте. Помогите пожалуйста. Имеется код, где производится случайный выбор из базы данных Access вопросов и требуется ответить на них. Как правильно написать, чтобы не было повторений вопросов, а также менялся вывод порядка ответов на вопросы.
А также как сделать, чтобы в итоге высвечивалась:
-максимально возможная сумма баллов;
-набранная тестируемым сумма баллов и ее % от максимума;
-правильные ответы на те вопросы, по которым тестируемый дал неверные ответ.
Спасибо
Код:

private
    procedure Vopros(nomer:integer);
  public
    { Public declarations }
  end;

var
  testing: Ttesting;
  mass: array of integer; //ìàññèâ

implementation

uses DM, Unit1;

{$R *.dfm}

procedure FillArray(var A: array of Integer);
var
  I, S, R: Integer;
begin
  for I := 0 to High(A) do
    A[I] := I;
  for i := High(A) downto 0 do
  begin
    R := Random(I);
    S := A[R];
    A[R] := A[I];
    A[I] := S;
  end;
end;

procedure Ttesting.Vopros(nomer:integer);
begin
DataModule2.Vopros.Locate('Номер',mass[nomer],[]);
//Варианты ответов
DataModule2.Variant.First;
RadioButton1.Caption:=DataModule2.Variant.FieldValues['Ответ'];
if DataModule2.Variant.FieldValues['Правильный']=true then
RadioButton1.Tag:=1 else RadioButton1.Tag:=0;

DataModule2.Variant.Next;
RadioButton2.Caption:=DataModule2.Variant.FieldValues['Ответ'];
if DataModule2.Variant.FieldValues['Правильный']=true then
RadioButton2.Tag:=1 else RadioButton2.Tag:=0;

DataModule2.Variant.Next;
RadioButton3.Caption:=DataModule2.Variant.FieldValues['Ответ'];
if DataModule2.Variant.FieldValues['Правильный']=true then
RadioButton3.Tag:=1 else RadioButton3.Tag:=0;

DataModule2.Variant.Next;
RadioButton4.Caption:=DataModule2.Variant.FieldValues['Ответ'];
if DataModule2.Variant.FieldValues['Правильный']=true then
RadioButton4.Tag:=1 else RadioButton4.Tag:=0;
Label2.Caption:=inttostr(strtoint(Label2.Caption)+1);
end;

procedure Ttesting.Button1Click(Sender: TObject);
var i:integer;
    RB:TRadioButton;
    cena:string;
begin
  if ((RadioButton1.Checked=true) or
  (RadioButton2.Checked=true) or
  (RadioButton3.Checked=true) or
  (RadioButton4.Checked=true) )
  then
  begin
  for i := 0 to GroupBox1.ControlCount-1 do
  begin
    RB:=TRadioButton(GroupBox1.Controls[i]);
    if RB.Checked=true then
    Label1.Caption:=inttostr(strtoint(Label1.Caption)+RB.Tag);
  end;
  if strtoint(Label2.Caption)<6 then
  begin
    Vopros(strtoint(Label2.Caption));
    RadioButton1.Checked:=false;
    RadioButton2.Checked:=false;
    RadioButton3.Checked:=false;
    RadioButton4.Checked:=false;
  testing.Caption:='Тестирование. Вопрос '+inttostr(strtoint(Label2.Caption)-1)+' из 50';
  end else
  begin
    if strtoint(Label1.Caption)>8 then
    cena:='5' else
    if strtoint(Label1.Caption)>6 then
    cena:='4' else
    if strtoint(Label1.Caption)>4 then
    cena:='3' else
    cena:='2';
    if MessageDlg('Набрано баллов '+Label1.Caption+'.'+#13+
    'Ваша оценка: '+cena+'!',
  mtConfirmation, [mbYes], 0)=mrYes then
  Form1.Visible:=true;
  testing.Close;
  Label2.Caption:='1';
  Label1.Caption:='0';
  RadioButton1.Checked:=false;
  RadioButton2.Checked:=false;
  RadioButton3.Checked:=false;
  RadioButton4.Checked:=false;
  end;
  end else
  showmessage('Вы не выбрали вариант ответа!');
end;

procedure Ttesting.Button2Click(Sender: TObject);
var i,kol:integer;
begin
For i:=1 to DataModule2.Vopros.RecordCount do
begin
  DataModule2.Vopros.Edit;
  DataModule2.Vopros.FieldValues['Номер']:=i;
  DataModule2.Vopros.Post;
  DataModule2.Vopros.Next;
end;
DataModule2.Vopros.Last;
kol:=DataModule2.Vopros.FieldValues['id'];
  Randomize;
  SetLength(mass,kol);
  FillArray(mass);
Vopros(strtoint(Label2.Caption));
testing.Caption:='Тестирование. Вопрос 1 из 20';
end;


Студент-2000 21.12.2017 03:04

Не знаю, но можно поискать функцию рандомизации массива. Или удалять из массива вопросы, которые были заданы.


Часовой пояс GMT +4, время: 20:24.

Powered by vBulletin® Version 4.5.3
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.