1 unit Unit1_test;
2
3 interface
4
5 uses
6 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
7 Dialogs, StdCtrls;
8
9 type
10 TForm1 = class(TForm)
11 Edit1: TEdit;
12 Edit2: TEdit;
13 ComboBox1: TComboBox;
14 Button1: TButton;
15 Label1: TLabel;
16 procedure Button1Click(Sender: TObject);
17 function MyCalculator(var a,b:Real):Real;
18 private
19 { Private declarations }
20 public
21 { Public declarations }
22 end;
23
24 var
25 Form1: TForm1;
26
27 implementation
28
29 {$R *.dfm}
30
31 procedure TForm1.Button1Click(Sender: TObject);
32 var
33 a,b:Real;
34 result1:Real;
35 begin
36 a:=StrToFloat(Edit1.Text);
37 b:=StrToFloat(Edit2.Text);
38 result1:=MyCalculator(a,b);
39 Label1.Caption:=FloatToStr(result1);
40 end;
41
42
43 function TForm1.MyCalculator(var a, b: Real): Real;
44
45 begin
46 case
47 ComboBox1.ItemIndex of
48 0: result:=a+b;
49 1: result:=a-b;
50 2: result:=a*b;
51 3: result:=a/b;
52 end;
53 end;
54
55
56 {
57 function TForm1.MyCalculator(var a, b: Real): Real;
58 begin
59 if ComboBox1.Text='+' then result:=a+b ;
60 if ComboBox1.Text='-' then result:=a-b ;
61 if ComboBox1.Text='*' then result:=a*b ;
62 if ComboBox1.Text='/' then result:=a/b ;
63 end;
64 }
65
66 {
67 procedure TForm1.Button1Click(Sender: TObject);
68 var
69 a,b:Real;
70 result:Real;
71 begin
72 a:=StrToFloat(Edit1.Text);
73 b:=StrToFloat(Edit2.Text);
74 if ComboBox1.Text='+' then result:=a+b ;
75 if ComboBox1.Text='-' then result:=a-b ;
76 if ComboBox1.Text='*' then result:=a*b ;
77 if ComboBox1.Text='/' then result:=a/b ;
78 Label1.Caption:=FloatToStr(result);
79 end;
80 }
81
82 end.
1 program Project_calculator;
2
3 uses
4 Forms,
5 Unit1_test in 'Unit1_test.pas' {Unit1_test};
6
7 {$R *.res}
8
9 begin
10 Application.Initialize;
11 Application.CreateForm(TForm1, Form1);
12 Application.Run;
13 end
![]()