
Interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Label1: TLabel;
Label2: TLabel;
Edit1: TEdit;
Edit2: TEdit;
RadioButton1: TRadioButton;
RadioButton2: TRadioButton;
RadioButton3: TRadioButton;
Label3: TLabel;
procedure RadioButton1Click(Sender: TObject);
procedure RadioButton2Click(Sender: TObject);
procedure RadioButton3Click(Sender: TObject);
procedure Edit1KeyPress(Sender: TObject; var Key: Char);
procedure Edit2KeyPress(Sender: TObject; var Key: Char);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
Implementation
{$R *.dfm}
procedure TForm1.RadioButton1Click(Sender: TObject);
begin
label1.caption:='Напряжение (вольт)';
label2.caption:='Сопротивление (Ом)';
label3.Caption:='';
edit1.Text:='';
edit2.Text:='';
end;
procedure TForm1.RadioButton2Click(Sender: TObject);
begin
label1.caption:='Ток (амперы)';
label2.caption:='Сопротивление (ом)';
label3.Caption:='';
edit1.Text:='';
edit2.Text:='';
end;
procedure TForm1.RadioButton3Click(Sender: TObject);
begin
label1.caption:='Ток (амперы)';
label2.caption:='Напряжение (вольт)';
label3.Caption:='';
edit1.Text:='';
edit2.Text:='';
end;
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
case key of
'0'..'9',#8: ;
#13: Edit2.SetFocus;
'.',',':
begin
if key = '.' then key := ',';
if pos (',',Edit1.Text) <> 0 then key := chr(0);
end;
else key := chr(0);
end;
end;
procedure TForm1.Edit2KeyPress(Sender: TObject; var Key: Char);
begin
case key of
'0'..'9',#8: ;
#13: Edit2.SetFocus;
'.',',':
begin
if key = '.' then key := ',';
if pos (',',Edit1.Text) <> 0 then key := chr(0);
end;
else key := chr(0);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if RadioButton1.Checked then
label3.Caption:=floattostr(strtofloat(edit1.text)/strtofloat(edit2.text))
else
begin
if RadioButton2.Checked then
label3.Caption:=floattostr(strtofloat(edit1.text)*strtofloat(edit2.text))
else
label3.Caption:=floattostr(strtofloat(edit2.text)/strtofloat(edit1.text));
end;
end;
end.
Результат работы программы:
Задача 3 самостоятельная:
Код программы:
unit Unit1;
Interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Label4: TLabel;
Label5: TLabel;
Button1: TButton;
procedure Edit1KeyPress(Sender: TObject; var Key: Char);
procedure Edit2KeyPress(Sender: TObject; var Key: Char);
procedure Edit3KeyPress(Sender: TObject; var Key: Char);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
a,b,c,p:real;