Визуальное программирование
Задание 3:Составить тест, содержащий 2 текстовых файла. В первом файле содержатся вопросы с ответами, во втором результат выполнения теста.
Предусмотреть ввод информации о тестируемом.
Код программы:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
Label1: TLabel; Label2: TLabel; Label3: TLabel; Label4: TLabel; Label5: TLabel; Label6: TLabel;
Button2: TButton; Button3: TButton; Button1: TButton;
RadioButton1: TRadioButton; RadioButton2: TRadioButton;
Edit1: TEdit; Edit2: TEdit; Edit3: TEdit;
RadioButton3: TRadioButton; RadioButton4: TRadioButton;
Timer1: TTimer;
procedure Button3Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private { Private declarations }
public { Public declarations }
end;
var
Form1: TForm1; f,ff:textfile;
i,n,kol,j:integer; p,s,s1,s2,s3,s4,k,ss:string; o:boolean;
a:array[1..10] of string;
b:array[1..30] of string;
implementation
{$R *.dfm}
procedure TForm1.Button3Click(Sender: TObject);
begin form1.close; end;
procedure TForm1.Button2Click(Sender: TObject);
begin
if o=true then
begin
if (radiobutton1.checked) and (radiobutton1.caption=p) then kol:=kol+1;
if (radiobutton2.checked) and (radiobutton2.caption=p) then kol:=kol+1;
if (radiobutton3.checked) and (radiobutton3.caption=p) then kol:=kol+1;
if (radiobutton4.checked) and (radiobutton4.caption=p) then kol:=kol+1;
if i>5 then
begin
assignfile(ff,'b.txt'); append(ff);
writeln(ff,'Дата '+datetostr(date)); writeln(ff,'Время '+timetostr(time)); writeln(ff,'Результаты теста: ');
if (kol=0) or (kol=5) then
writeln(ff,'Вы ответили правильно на '+inttostr(kol)+' вопросов- ',floattostr((kol*100)/5),'% правильных ответов');
if (kol=2) or (kol=3) or (kol=4) then
writeln(ff,'Вы ответили правильно на '+inttostr(kol)+' вопроса- ',floattostr((kol*100)/5),'% правильных ответов');
if ((kol*100)/5)<55 then writeln(ff,'Ваша оценка - неудовлетворительно')
else
if((kol*100)/5)<71 then writeln(ff,'Ваша оценка - удовлетворительно')
else
if((kol*100)/5)<86 then writeln(ff,'Ваша оценка - хорошо')
else writeln(ff,'Ваша оценка - отлично') ;
ss:=''; closefile(ff); reset(ff);
while not eof(ff) do
begin
readln(ff,s); ss:=ss+s+chr(13);
end;
showmessage(ss); form1.Close;
end
else
begin
if i=1 then p:=b[j+2] else
if i=2 then p:=b[j+3] else
if i=3 then p:=b[j] else
if i=4 then p:=b[j+1] else
if i=5 then p:=b[j];
radiobutton2.checked:=false; radiobutton1.Checked:=false;
radiobutton3.checked:=false; radiobutton4.checked:=false;
label1.Caption:='Вопрос №'+inttostr(i)+': '; label2.Caption:=a[i];
radiobutton1.Caption:=b[j]; radiobutton2.Caption:=b[j+1];
radiobutton3.Caption:=b[j+2]; radiobutton4.Caption:=b[j+3];
inc(i); j:=j+4;
end;
end
else
showmessage('Заполните информацию о себе');
end;
procedure TForm1.FormCreate(Sender: TObject);
var v,w:integer;
begin
Label1.Visible := false; Label2.Visible := false; Label3.Visible := false;
RadioButton1.Visible := false; RadioButton2.Visible := false;
RadioButton3.Visible := false; RadioButton4.Visible := false;
Button2.Visible := false; Button3.Visible := false;
o:=false;
assignfile(f,'a.txt'); reset(f);
for v:=1 to 5 do
begin readln(f,s); a[v]:=s; end;
for w:=1 to 20 do
begin readln(f,s); b[w]:=s; end;
i:=1; j:=1;
label1.Caption:='Вопрос №'+inttostr(i)+': '; label2.Caption:=a[i];
radiobutton1.Caption:=b[j]; radiobutton2.Caption:=b[j+1];
radiobutton3.Caption:=b[j+2]; radiobutton4.Caption:=b[j+3];
p:=b[i+1]; i:=i+1; j:=j+4;
end;
procedure TForm1.Button1Click(Sender: TObject);
var f,i,g:string;
begin
Label1.Visible := true; Label2.Visible := true; Label3.Visible := true;
RadioButton1.Visible := true; RadioButton2.Visible := true;
RadioButton3.Visible := true; RadioButton4.Visible := true;
Button2.Visible := true; Button3.Visible := true; Timer1.Enabled := true;
assignfile(ff,'b.txt'); append(ff);
f:= edit1.text; i:= edit2.text ; g:= edit3.text;
if (edit1.text='') or (edit2.text='') or (edit3.text='') then showmessage('Заполните все поля!')
else
begin writeln(ff,f); writeln(ff,i); writeln(ff,g); end;
closefile(ff); o:=true;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin Caption := TimeToStr(Time); end;
end.
Поиск по сайту:
|