РАЗРАБОТКА АЛГОРИТМА ПОСТАЛЕННОЙ ЗАДАЧИ (БЛОК-СХЕМА)
ПРОГРАММНЫЙ КОД Unit Unit1; Interface Uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Math, ExtCtrls, XPMan, Menus; Type TForm1 = class(TForm) XPManifest1: TXPManifest; MainMenu1: TMainMenu; N1: TMenuItem; f5: TMenuItem; procedure N1Click(Sender: TObject); procedure f5Click(Sender: TObject); Private { Private declarations } Public { Public declarations } End; Var Form1: TForm1; X: boolean; z: Extended; R: string; Implementation Uses Unit2, Unit3; {$R *.dfm} procedure TForm1.N1Click(Sender: TObject); Begin Form2.Show; End; procedure TForm1.f5Click(Sender: TObject); Begin Form3.Show; End; End. Unit Unit2; Interface Uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, math, ExtCtrls, jpeg; Type TForm2 = class(TForm) Edit1: TEdit; Label1: TLabel; Button1: TButton; Label2: TLabel; Image1: TImage; Panel1: TPanel; Label5: TLabel; Label3: TLabel; Edit2: TEdit; procedure Button1Click(Sender: TObject); procedure Edit1KeyPress(Sender: TObject; var Key: Char); Private { Private declarations } Public { Public declarations } End; Var Form2: TForm2; Implementation {$R *.dfm} procedure TForm2.Button1Click(Sender: TObject); var C,d,k,n,i: longint; Begin if (edit1.text<>'') or (edit2.text<>'')then Begin k:= strtoint(edit2.text); n:= strtoint(edit1.text); if (k>n) or (k<0) or (n<0) then label1.Caption:='Ошибка: не может быть k>n' Else begin if k>n div 2 then k:=n-k; d:=1; for i:=1 to k do d:=d*(n-i+1) div i; C:=d; label1.Caption:=inttostr(C); End; End else label1.Caption:='Ошибка: Введите заничения'; End; procedure TForm2.Edit1KeyPress(Sender: TObject; var Key: Char); Begin If Key in ['0'..'9', #8, '-', ','] then Begin if (Key in [',']) and (Pos(',', Edit1.Text)>0) then Key:=#0; End else Key:=#0; End; End. Unit Unit3; Interface Uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls; Type TForm3 = class(TForm) Button1: TButton; Label1: TLabel; Edit1: TEdit; Edit2: TEdit; Label2: TLabel; Label3: TLabel; Image1: TImage; Label4: TLabel; Panel1: TPanel; Label5: TLabel; Label6: TLabel; procedure Button1Click(Sender: TObject); procedure Edit1KeyPress(Sender: TObject; var Key: Char); procedure Edit2KeyPress(Sender: TObject; var Key: Char); Private { Private declarations } Public { Public declarations } End; Var Form3: TForm3; Implementation {$R *.dfm} procedure TForm3.Button1Click(Sender: TObject); var A, z: Extended; Begin if edit1.text<>'' then Begin z:=strtofloat(edit1.text); if edit2.text<>'' then Begin if z>0 then Begin A:=sqr(pi)*z; label1.Caption:=floattostr(round(A))+' '+ edit2.text+' в квадрате'; End else label1.Caption:='Ошибка: Радиус не может быть отритцательным или равным нулю.'; End else label1.Caption:='Ошибка: Введите наименование велечины измерения.'; End else label1.Caption:='Ошибка: Введите значение'; End; procedure TForm3.Edit1KeyPress(Sender: TObject; var Key: Char); Begin If Key in ['0'..'9', #8, '-', ','] then Begin if Key in [','] then Begin if Pos(',', Edit1.Text)>0 then Key:=#0; End; End else Key:=#0; End; procedure TForm3.Edit2KeyPress(Sender: TObject; var Key: Char); Begin If Key in ['0'..'9', '-', ',', '\','/', '.'] then Key:=#0; End; End.
|