close

Вход

Забыли?

вход по аккаунту

?

Приложение А (2)

код для вставкиСкачать
Приложение А - исходные тексты программных модулей
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls, TabNotBk, Grids, ExtCtrls,ComObj;
type
TForm1 = class(TForm)
TabbedNotebook1: TTabbedNotebook;
Button1: TButton;
Edit1: TEdit;
Edit3: TEdit;
Edit4: TEdit;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Memo1: TMemo;
strngrd1: TStringGrid;
label2: TLabel;
label3: TLabel;
label7: TLabel;
edit5: TEdit;
edit6: TEdit;
button3: TButton;
strngrd2: TStringGrid;
button4: TButton;
label8: TLabel;
strngrd4: TStringGrid;
button5: TButton;
strngrd3: TStringGrid;
button6: TButton;
label9: TLabel;
Button2: TButton;
Image1: TImage;
label10: TLabel;
label11: TLabel;
label12: TLabel;
label13: TLabel;
label14: TLabel;
button9: TButton;
button8: TButton;
procedure Button1Click(Sender: TObject);
procedure button3Click(Sender: TObject);
procedure button4Click(Sender: TObject);
procedure button5Click(Sender: TObject);
procedure button6Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
//procedure Button7Click(Sender: TObject);
procedure button9Click(Sender: TObject);
procedure label10MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure label10MouseLeave(Sender: TObject);
procedure label11MouseLeave(Sender: TObject);
procedure label11MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure label12MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure label12MouseLeave(Sender: TObject);
procedure label13MouseLeave(Sender: TObject);
procedure label13MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure label14MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure label14MouseLeave(Sender: TObject);
procedure Edit1KeyPress(Sender: TObject; var Key: Char);
procedure Edit3KeyPress(Sender: TObject; var Key: Char);
procedure Edit4KeyPress(Sender: TObject; var Key: Char);
procedure edit5KeyPress(Sender: TObject; var Key: Char);
procedure edit6KeyPress(Sender: TObject; var Key: Char);
procedure button8Click(Sender: TObject);
procedure label10Click(Sender: TObject);
procedure label11Click(Sender: TObject);
procedure label13Click(Sender: TObject);
procedure label14Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
const
eps=0.001;
putname='g:\KURSOVOY PROEKT\KURSOVOY PROEKT-Boor\Kursovoy proekt\1\document.doc';
var
Form1: TForm1;
Massiv_A:array of Real;
Massiv_B:array of array of Integer;
Massiv_B2:array of array of Integer;
Massiv_C:array of real;
Massiv_C2:array of real;
n:integer;
Word: variant;
implementation
uses MaskUtils;
{$R *.dfm}
function kontrol_function(x:real):real;
begin
kontrol_function:=1-1/exp(0.25*ln(1+x));
end;
function summa_rayda (x:real):Real;
var i:Integer;
chisl,znam,zn,sum,sm1,sm2,sl:Real;
begin
zn:=1;
i:=2;
chisl:=1 ;
znam:=4;
sm2:=x;
sum:=(chisl/znam)*x;
repeat
zn:=zn*(-1) ;
chisl:=chisl*(4*i-3);
znam:=znam*(4*i);
sm2:=sm2*x;
sl:=zn*(chisl/znam)*sm2;
sum:=sum+sl;
inc(i);
until Abs(sl)<eps;
summa_rayda:=sum;
end;
procedure TForm1.Button1Click(Sender: TObject); // Формирование массива А
var
i:Integer;
h,rez,sum,x_na4,x_kon:Real;
begin
SetLength(Massiv_A,i);
i:=0;
x_na4:=StrToFloat(edit1.Text);
x_kon:=StrToFloat(Edit3.Text);
h:=StrTofloat(Edit4.Text);
Memo1.Clear;
repeat
inc(i);
rez:=summa_rayda(x_na4);
Massiv_A[i]:=rez;
memo1.Lines.Add('A['+inttostr(i)+']='+FloatToStrF(rez,ffFixed,3,3)+' '+'X='+FloatToStrf(kontrol_function(x_na4),ffFixed,3,3));
x_na4:=x_na4+h;
until x_na4>x_kon ;
n:=i;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
x,y,Xmin,Xmax,Ymin,Ymax:real;
Xgmin,Xgmax,Ygmax,Ygmin,i,Xg,Yg:integer;
begin
Xgmin:=0;
Xgmax:= Image1.ClientWidth;
Ygmin:= Image1.ClientHeight;
Ygmax:=0;
Xmin:=0;
Xmax:= n-1;
Ymin:=massiv_c2[n-1];
Ymax:=massiv_c2[0];
Xg:=Xgmin + Trunc((Xgmax-Xgmin)*(0-Xmin)/(Xmax-Xmin));
Yg:=Ygmin + Trunc((Ygmax-Ygmin)*(massiv_c2[0]-Ymin)/(Ymax-Ymin));
Image1.Canvas.Moveto(Xg,Yg);
for i:= 1 to n-1 do begin
image1.Canvas.Pen.Color:=clGreen;
Xg:=Xgmin + Trunc((Xgmax-Xgmin)*(i-Xmin)/(Xmax-Xmin));
Yg:=Ygmin + Trunc((Ygmax-Ygmin)*(massiv_c2[i]-Ymin)/(Ymax-Ymin));
Image1.Canvas.Lineto(Xg,Yg);
end;
Xg:=Xgmin + Trunc((Xgmax-Xgmin)*(0-Xmin)/(Xmax-Xmin));
Yg:=Ygmin + Trunc((Ygmax-Ygmin)*(massiv_c[0]-Ymin)/(Ymax-Ymin));
Image1.Canvas.Moveto(Xg,Yg);
for i:= 1 to n-1 do begin
image1.Canvas.Pen.Color:=clBlue;
Xg:=Xgmin + Trunc((Xgmax-Xgmin)*(i-Xmin)/(Xmax-Xmin));
Yg:=Ygmin + Trunc((Ygmax-Ygmin)*(massiv_c[i]-Ymin)/(Ymax-Ymin));
Image1.Canvas.Lineto(Xg,Yg);
end;
image1.Canvas.Pen.Color:=clred;
xg:=0;
Yg:=Ygmin + Trunc((Ygmax-Ygmin)*(0-Ymin)/(Ymax-Ymin));
Image1.Canvas.Moveto(Xg,Yg);
xg:=Image1.ClientWidth;
Image1.Canvas.Lineto(Xg,Yg);
image1.Canvas.Pen.Color:=clred;
image1.Canvas.Moveto(0,0);
Image1.Canvas.Lineto(0,1000);
end;
procedure TForm1.button3Click(Sender: TObject); //заполнение массива В
var vg,ng,i,j:Integer;
begin
randomize;
SetLength(Massiv_B,n,n);
ng:=StrToInt(edit5.text);
vg:=StrToInt(edit6.text);
strngrd1.RowCount:=n;
strngrd1.ColCount:=n;
for i:=0 to n-1 do begin
for j:=0 to n-1 do begin
Massiv_B[i,j]:=ng+(Random(vg-ng+1));
strngrd1.Cells[j,i]:=IntToStr(Massiv_B[i,j]);
end;
end;
end;
procedure TForm1.button4Click(Sender: TObject);
var k,a,rez,i,j:Integer;
begin
SetLength(Massiv_B2,n,n);
SetLength(Massiv_C,n);
SetLength(Massiv_C2,n);
strngrd2.RowCount:=n;
strngrd2.ColCount:=1;
For i:= 0 to n-1 do
begin
For j:=0 to n-1 do
Massiv_C[i]:=massiv_c[i]+massiv_b2[i,j]*massiv_a[j];
Massiv_C2[i]:=massiv_c[i];
strngrd2.Cells[0,i]:=FloatToStrF(massiv_C[i],ffGeneral,3,3);
end;end;
procedure TForm1.button5Click(Sender: TObject);
var i,j,k:integer;
m:real;
begin
setLength(Massiv_C2,n);
for i:= 0 to n-1 do Massiv_C2[i]:=Massiv_C[i];
For i:=n-1 downTo 1 do
begin
k:=i;
m:=Massiv_C2[i];
for j:=0 to i-1 do
if Massiv_C2[j]<m then
begin k:=j; m:=Massiv_C2[j]
end;
if k<>i then begin
Massiv_C2[k]:=Massiv_C2[i]; Massiv_C2[i]:=m;
end;
end;
strngrd4.RowCount:=n;
for i:=0 to n-1 do
strngrd4.Cells[0,i]:=formatfloat('0.000',Massiv_C2[i]);
end;
procedure TForm1.button6Click(Sender: TObject);
var i,j,k:integer;
begin
SetLength(Massiv_B2,n,n);
strngrd3.RowCount:=n;
strngrd3.ColCount:=n;
For i:= 0 to n-1 do
For j:=0 to n-1 do
For k:= 0 to n-1 do
Massiv_B2[i,j]:= massiv_b2[i,j]+massiv_B[i,k]*massiv_B[k,j];
For i:= 0 to n-1 do
For j:=0 to n-1 do
strngrd3.Cells[j,i]:=IntToStr(massiv_b2[i,j]);
end;
procedure TForm1.button9Click(Sender: TObject);
var i,j:Integer;
begin
try
Word := CreateOleObject('Word.Application');
Word.Documents.Add;
Word.activedocument.range.InsertAfter('Массив А'+#10#13+Memo1.Text+#10+'Массив В'+#10#13);
with strngrd1 do
for i := 0 to n - 1 do begin
for j := 0 to n - 1 do begin
Word.activedocument.range.InsertAfter(Cells[j,i]+' ');
end;
Word.activedocument.range.InsertAfter(#10);
end;
Word.activedocument.range.InsertAfter('Массив В^2'+#10#13);
with strngrd3 do
for i:= 0 to n - 1 do begin
for j:= 0 to n - 1 do begin
Word.activedocument.range.InsertAfter(Cells[j,i]+' ');
end;
Word.activedocument.range.InsertAfter(#10);
end;
Word.activedocument.range.InsertAfter('Массив C'+#10#13);
with strngrd2 do
for i:= 0 to n - 1 do begin
Word.activedocument.range.InsertAfter(Cells[0,i]+#10);
end;
Word.activedocument.range.InsertAfter('Отсортированный Массив C'+#10#13);
with strngrd4 do
for i:= 0 to n - 1 do begin
Word.activedocument.range.InsertAfter(Cells[0,i]+#10);
end;
word.ActiveDocument.SaveAs(putname);
if Word.ActiveDocument.Saved then
messagebox(handle,'Документ сохранен!','Внимание!',0);///
if not Word.ActiveDocument.Saved then
messagebox(handle,'Документ не сохранен!','Внимание!',0);
except
ShowMessage('НЕ могу запустить MS Word');
end;
Word.Application.Documents.Close;
Word.Quit;
Word:=UnAssigned;
end;
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
if not (key in ['0'..'9','-',#8,DecimalSeparator]) then key:=#0;
end;
procedure TForm1.Edit3KeyPress(Sender: TObject; var Key: Char);
begin
if not (key in ['0'..'9','-',#8,DecimalSeparator]) then key:=#0;
end;
procedure TForm1.Edit4KeyPress(Sender: TObject; var Key: Char);
begin
if not (key in ['0'..'9','-',#8,DecimalSeparator]) then key:=#0;
end;
procedure TForm1.edit5KeyPress(Sender: TObject; var Key: Char);
begin
if not (key in ['0'..'9','-',#8,DecimalSeparator]) then key:=#0;
end;
procedure TForm1.edit6KeyPress(Sender: TObject; var Key: Char);
begin
if not (key in ['0'..'9','-',#8,DecimalSeparator]) then key:=#0;
end;
procedure TForm1.label10MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
label10.Font.Color:=clBlue;
end;
procedure TForm1.label10MouseLeave(Sender: TObject);
begin
label10.Font.Color:=clBlack;
end;
procedure TForm1.label11MouseLeave(Sender: TObject);
begin
label11.Font.Color:=clBlack;
end;
procedure TForm1.label11MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
label11.Font.Color:=clBlue;
end;
procedure TForm1.label12MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
label12.Font.Color:=clBlue;
end;
procedure TForm1.label12MouseLeave(Sender: TObject);
begin
label12.Font.Color:=clBlack;
end;
procedure TForm1.label13MouseLeave(Sender: TObject);
begin
label13.Font.Color:=clBlack;
end;
procedure TForm1.label13MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
label13.Font.Color:=clBlue;
end;
procedure TForm1.label14MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
label14.Font.Color:=clBlue;
end;
procedure TForm1.label14MouseLeave(Sender: TObject);
begin
label14.Font.Color:=clblack;
end;
procedure TForm1.button8Click(Sender: TObject);
begin
Word := CreateOleObject('Word.Application');
word.Visible:=True;
Word.Documents.add(putname)
end;
procedure spravka;
var
h1 : HWND; // идентификатор (дескриптор) окна
begin
h1:= FindWindow('HH Parent','Массив А');
if h1=0 then
WinExec('hh.exe Help.chm',SW_RESTORE)
else
begin
ShowWindow(h1,SW_RESTORE);
Windows.SetForegroundWindow(h1);
end; end;
procedure TForm1.label10Click(Sender: TObject);
begin
spravka;
end;
procedure TForm1.label11Click(Sender: TObject);
begin
spravka;
end;
procedure TForm1.label13Click(Sender: TObject);
begin
spravka;
end;
procedure TForm1.label14Click(Sender: TObject);
begin
spravka;
end;
end.
Документ
Категория
Рефераты
Просмотров
14
Размер файла
228 Кб
Теги
приложение
1/--страниц
Пожаловаться на содержимое документа