Переменные
i,j:integer;
Процедура расчета мер близости на отношениях
procedure TForm1.BitBtn1Click(Sender: TObject);
var sum:integer;
oc:real;
begin
oc:=0;
for i := 0 to StringGrid1.ColCount-1 do
for j := 0 to StringGrid1.RowCount-1 do
begin
if checkbox1.Checked then
begin
if i>j then
oc:=oc+abs(strtofloat(Stringgrid1.Cells[i,j])-
strtofloat(stringgrid2.Cells[i,j]))
end
else oc:=oc+abs(strtofloat(Stringgrid1.Cells[i,j])-
strtofloat(stringgrid2.Cells[i,j]));
end;
if checkbox1.Checked<>true then
oc:=oc/2;
showmessage('d(P1,P2)='+floattostr(oc));
end;
Блок-схема
Процедура изменения размерности матриц
procedure TForm1.Change_(Sender: TObject);
begin
if edit1.Text='' then exit;
stringgrid1.ColCount:=strtoint(edit1.text);
stringgrid1.RowCount:=strtoint(edit1.text);
stringgrid2.ColCount:=strtoint(edit1.text);
stringgrid2.RowCount:=strtoint(edit1.text);
end;
Исходник
Unit1.pas
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, StdCtrls, ComCtrls, Buttons, Menus;
type
TForm1 = class(TForm)
StringGrid1: TStringGrid;
StringGrid2: TStringGrid;
Edit1: TEdit;
StatusBar1: TStatusBar;
BitBtn1: TBitBtn;
MainMenu1: TMainMenu;
N1: TMenuItem;
N2: TMenuItem;
N3: TMenuItem;
CheckBox1: TCheckBox;
procedure BitBtn1Click(Sender: TObject);
procedure Change_(Sender: TObject);
procedure N3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
i,j:integer;
implementation
{$R *.dfm}
procedure TForm1.BitBtn1Click(Sender: TObject);
var sum:integer;
oc:real;
begin
oc:=0;
for i := 0 to StringGrid1.ColCount-1 do
for j := 0 to StringGrid1.RowCount-1 do
begin
if checkbox1.Checked then
begin
if i>j then
oc:=oc+abs(strtofloat(Stringgrid1.Cells[i,j])-
strtofloat(stringgrid2.Cells[i,j]))
end
else oc:=oc+abs(strtofloat(Stringgrid1.Cells[i,j])-
strtofloat(stringgrid2.Cells[i,j]));
end;
if checkbox1.Checked<>true then
oc:=oc/2;
showmessage('d(P1,P2)='+floattostr(oc));
end;
procedure TForm1.Change_(Sender: TObject);
begin
if edit1.Text='' then exit;
stringgrid1.ColCount:=strtoint(edit1.text);
stringgrid1.RowCount:=strtoint(edit1.text);
stringgrid2.ColCount:=strtoint(edit1.text);
stringgrid2.RowCount:=strtoint(edit1.text);
end;
procedure TForm1.N3Click(Sender: TObject);
begin
close;
end;
end.
unit1.dfm
object Form1: TForm1
Left = 281
Top = 211
Width = 722
Height = 298
Caption = #1052#1077#1088#1099' '#1073#1083#1080#1079#1086#1089#1090#1080' '#1085#1072' '#1086#1090#1085#1086#1096#1077#1085#1080#1103#1093
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
Menu = MainMenu1
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object StringGrid1: TStringGrid
Left = 16
Top = 40
Width = 337
Height = 169
FixedCols = 0
FixedRows = 0
Options = [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine, goRangeSelect, goEditing]
TabOrder = 0
end
object StringGrid2: TStringGrid
Left = 360
Top = 40
Width = 345
Height = 169
FixedCols = 0
FixedRows = 0
Options = [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine, goRangeSelect, goEditing]
TabOrder = 1
end
object Edit1: TEdit
Left = 16
Top = 8
Width = 33
Height = 21
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = [fsBold]
ParentFont = False
TabOrder = 2
Text = '5'
OnChange = Change_
end
object StatusBar1: TStatusBar
Left = 0
Top = 225
Width = 714
Height = 19
Panels = <>
end
object BitBtn1: TBitBtn
Left = 216
Top = 8
Width = 129
Height = 25
Caption = #1056#1072#1089#1089#1095#1080#1090#1072#1090#1100
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = [fsBold]
ParentFont = False
TabOrder = 4
OnClick = BitBtn1Click
end
object CheckBox1: TCheckBox
Left = 56
Top = 8
Width = 153
Height = 17
Caption = #1085#1072#1076' '#1075#1083#1072#1074#1085#1086#1081' '#1076#1080#1072#1075#1072#1085#1072#1083#1100#1102
Checked = True
State = cbChecked
TabOrder = 5
end
object MainMenu1: TMainMenu
Left = 432
Top = 8
object N1: TMenuItem
Caption = #1060#1072#1081#1083
object N2: TMenuItem
Caption = '-'
end
object N3: TMenuItem
Caption = #1042#1099#1093#1086#1076
OnClick = N3Click
end
end
end
end
|