Подвійним натисненням клавіші “миші” на формі і кнопці Button1 створіть відповідні процедури обробки -подій. Використовуючи текст модуля UnZap, уважно наберіть оператори цих процедур.
Текст модуля UnZap
UnitUnZap;
Interface
Uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs
StdCtrls, Buttons, Grids;
Type
TForm1 = class(TForm)
StringGrid1: TStringGrid;
Button1: ТВutton;
procedureFormCreate(Sender: TObject);
procedureButton1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
Var
Form1: TForm1;
Implementation
{$R *.DFM}
Type
zap=record// оголошення запису
fio :string[20];
mat,fiz,soch:integer;
srbal :extended
end;
Var
MZap:array[1..9] zap; // оголошення масиву записів
procedureTForm1.FormCreate(Sender: TObject);
Var
i:integer;
Begin
withStringGrid1 do
begin// занесення інформації в середину StringGrid1
Cells[0,0]:='№пп’;
Cells[1,0]:='Фамилия,инициалы';
Cells[2,0]:='Математика';
Cells[3,0]:='Физика';
Cells[4,0]:='Сочинение';
Cells[5,0]:='Ср.балл';
fori:=1 to 9 do
Cells[0,i]:=IntToStr(i);
Cells[1,1]:='Первый П.П.'; Cells[2,1]:='3'; Cells[3,1]:='3'; Cells[4,1]:='3';
Cells[1,2]:='Второй В.В.'; Cells[2,2]:='3'; Cells[3,2]:='3'; Cells[4,2]:='4';
Cells[1,3]:='Третий Т.Т.'; Cells[2,3]:='3'; Cells[3,3]:='4'; Cells[4,3]:='4';
Cells[1,4]:='Четвертый Ч.Ч.'; Cells[2,4]:='4'; Cells[3,4]:='4'; Cells[4,4]:='4';
Cells[1,5]:='Пятый П.П.'; Cells[2,5]:='3'; Cells[3,5]:='4'; Cells[4,5]:='5';
Cells[1,6]:='Шестой Ш.Ш.'; Cells[2,6]:='5'; Cells[3,6]:='4'; Cells[4,6]:='4';
Cells[1,7]:='Седьмой С.С.'; Cells[2,7]:='5'; Cells[3,7]:='5'; Cells[4,7]:='4';
Cells[1,8]:='Восьмой В.В.'; Cells[2,8]:='5'; Cells[3,8]:='5'; Cells[4,8]:='5';
Cells[1,9]:='Девятый Д.Д.'; Cells[2,9]:='3'; Cells[3,9]:='5'; Cells[4,9]:='5';
fori:=1 to 9 do
withMZap[i] do
begin// формування полів масиву записів
fio:=Cells[1,i];
mat:=StrToInt(Cells[2,i]);
fiz:=StrToInt(Cells[3,i]);
soch:=StrToInt(Cells[4,i]);
srbal:=(mat+fiz+soch)/3; // обчислення значення середнього бала
Cells[5,i]:=FloatToStrF(srbal,ffFixed,5,2); // виведення значення середнього балла
end; // в останню колонку StringGrid1
end;
end;
procedureTForm1.Button1Click(Sender: TObject);
Var
i,j :integer;
vper:zap;
Begin
fori:=1 to 9 do
withStringGrid1,MZap[i] do
Begin
fio:=Cells[1,i];
mat:=StrToInt(Cells[2,i]);
fiz:=StrToInt(Cells[3,i]);
soch:=StrToInt(Cells[4,i]);
srbal:=(mat+fiz+soch)/3;
Cells[5,i]:=FloatToStrF(srbal,ffFixed,5,2);
end;
fori:=2 to 9 do // сортування методом "пухирця"
forj:=9 downto i do
ifMZap[j-1].srbal<MZap[j].srbal then
Begin
vper:=MZap[j-1];
MZap[j-1]:=MZap[j];
MZap[j]:=vper;
end;
for i:=1 to 9 do // заповнення осередків StringGrid1 полями масиву записів
withStringGrid1,MZap[i] do
Begin
Cells[1,i]:=fio;
Cells[2,i]:=IntToStr(mat);
Cells[3,i]:=IntToStr(fiz);
Cells[4,i]:=IntToStr(soch);
Cells[5,i]:=FloatToStrF(srbal,ffFixed,5,2);
end;
end;
End.