16.06.2019, 17:45. Показов 811. Ответов 0
Здравствуйте , столкнулся с проблемой при записи функций (sin, cos, Ln, Lg )в PascaABC.net в windows.forms. Вопрос такой : как правильно записать программу для функций в оконном приложение паскаль (писал калькулятор , простые действия получились , а с функциями беда ). Мне только с cos решить беду , а дальше я сам смогу по аналогии . Зарание спасибо :-).
| Pascal |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
| unit Unit1;
interface
uses System, System.Drawing, System.Windows.Forms;
type
calculator = class(Form)
procedure numb_click(sender: Object; e: EventArgs);
procedure delete_Click(sender: Object; e: EventArgs);
procedure point_Click(sender: Object; e: EventArgs);
procedure operation_Click(sender: Object; e: EventArgs);
procedure result_Click(sender: Object; e: EventArgs);
procedure Exp_Click(sender: Object; e: EventArgs);
procedure Pi_Click(sender: Object; e: EventArgs);
procedure Cos_Click(sender: Object; e: EventArgs);
procedure sin_Click(sender: Object; e: EventArgs);
procedure Ln_Click(sender: Object; e: EventArgs);
procedure Lg_Click(sender: Object; e: EventArgs);
procedure degree_Click(sender: Object; e: EventArgs);
{$region FormDesigner}
private
{$resource Unit1.calculator.resources}
wondow1: TextBox;
wondow2: TextBox;
delete: Button;
button1: Button;
button2: Button;
button3: Button;
button4: Button;
button5: Button;
button6: Button;
button7: Button;
button8: Button;
button9: Button;
button10: Button;
button16: Button;
button15: Button;
button14: Button;
button13: Button;
button12: Button;
button17: Button;
button18: Button;
button19: Button;
button20: Button;
button21: Button;
button22: Button;
button23: Button;
button11: Button;
{$include Unit1.calculator.inc}
{$endregion FormDesigner}
public
constructor;
begin
InitializeComponent;
end;
end;
implementation
const
pi = 3.14159265358979;
var
a, b, result, s: real;
operation: string;
procedure calculator.numb_Click(sender: Object; e: EventArgs);
begin
wondow1.text := wondow1.text + button(sender).text;
wondow2.text := wondow2.text + ' ' + button(sender).text;
end;
procedure calculator.delete_Click(sender: Object; e: EventArgs);
begin
wondow1.text := '';
wondow2.text := '';
a := 0;
b := 0;
end;
procedure calculator.point_Click(sender: Object; e: EventArgs);
begin
var
k := Pos('.', wondow1.Text);
if k = 0 then
wondow1.Text := wondow1.Text + '.';
wondow2.Text := wondow2.Text + '.';
end;
procedure calculator.operation_Click(sender: Object; e: EventArgs);
begin
a := real.Parse(wondow1.text);
operation := button(sender).text;
wondow1.Text := ' ';
wondow2.text := wondow2.text + ' ' + operation;
end;
procedure calculator.result_Click(sender: Object; e: EventArgs);
begin
b := real.Parse(wondow1.Text);
case operation[1] of
'+': result := a + b;
'-': result := a - b;
'*': result := a * b;
'/': result := a / b;
end;
wondow1.text := result.toString;
end;
procedure calculator.Exp_Click(sender: Object; e: EventArgs);
begin
wondow1.Text := wondow1.Text + '2,718281828459';
wondow2.Text := wondow2.Text + '2,718281828459';
end;
procedure calculator.Pi_Click(sender: Object; e: EventArgs);
begin
wondow1.Text := wondow1.Text + '3,14159265358979';
wondow2.Text := wondow2.Text + '3,14159265358979';
end;
procedure calculator.Cos_Click(sender: Object; e: EventArgs);
begin
result:=a*(pi/180);
wondow1.text:=result.tostring;
end;
procedure calculator.sin_Click(sender: Object; e: EventArgs);
begin
end;
procedure calculator.Ln_Click(sender: Object; e: EventArgs);
begin
end;
procedure calculator.Lg_Click(sender: Object; e: EventArgs);
begin
end;
procedure calculator.degree_Click(sender: Object; e: EventArgs);
begin
end;
end. |
|
Добавлено через 4 часа 20 минут
| Delphi |
1
2
3
4
5
6
7
| procedure calculator.Cos_Click(sender: Object; e: EventArgs);
begin
a := real.Parse(wondow1.text);
operation := button(sender).text;
var a := a*pi/z;
wondow1.text := a.tostring;
end; |
|
Я с косинусом решил вот так ,но он теперь выдает 0.532114775
Добавлено через 1 час 56 минут
| Delphi |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
| unit Unit1;
interface
uses System, System.Drawing, System.Windows.Forms;
const
pi = 3.14159265358979;
z = 180;
type
calculator = class(Form)
procedure numb_click(sender: Object; e: EventArgs);
procedure delete_Click(sender: Object; e: EventArgs);
procedure point_Click(sender: Object; e: EventArgs);
procedure operation_Click(sender: Object; e: EventArgs);
procedure result_Click(sender: Object; e: EventArgs);
procedure Exp_Click(sender: Object; e: EventArgs);
procedure Pi_Click(sender: Object; e: EventArgs);
procedure Cos_Click(sender: Object; e: EventArgs);
procedure sin_Click(sender: Object; e: EventArgs);
procedure Ln_Click(sender: Object; e: EventArgs);
procedure Lg_Click(sender: Object; e: EventArgs);
procedure degree_Click(sender: Object; e: EventArgs);
{$region FormDesigner}
private
{$resource Unit1.calculator.resources}
wondow1: TextBox;
wondow2: TextBox;
delete: Button;
button1: Button;
button2: Button;
button3: Button;
button4: Button;
button5: Button;
button6: Button;
button7: Button;
button8: Button;
button9: Button;
button10: Button;
button16: Button;
button15: Button;
button14: Button;
button13: Button;
button12: Button;
button17: Button;
button18: Button;
sin: Button;
cos: Button;
button21: Button;
button22: Button;
degree: Button;
button11: Button;
{$include Unit1.calculator.inc}
{$endregion FormDesigner}
public
constructor;
begin
InitializeComponent;
end;
end;
implementation
var
a, b, result, s: real;
operation: string;
procedure calculator.numb_Click(sender: Object; e: EventArgs);
begin
wondow1.text := wondow1.text + button(sender).text;
wondow2.text := wondow2.text + ' ' + button(sender).text;
end;
procedure calculator.delete_Click(sender: Object; e: EventArgs);
begin
wondow1.text := '';
wondow2.text := '';
a := 0;
b := 0;
end;
procedure calculator.point_Click(sender: Object; e: EventArgs);
begin
var
k := Pos('.', wondow1.Text);
if k = 0 then
wondow1.Text := wondow1.Text + '.';
wondow2.Text := wondow2.Text + '.';
end;
procedure calculator.operation_Click(sender: Object; e: EventArgs);
begin
a := real.Parse(wondow1.text);
operation := button(sender).text;
wondow1.Text := ' ';
wondow2.text := wondow2.text + ' ' + operation;
end;
procedure calculator.result_Click(sender: Object; e: EventArgs);
begin
b := real.Parse(wondow1.Text);
case operation[1] of
'+': result := a + b;
'-': result := a - b;
'*': result := a * b;
'/': result := a / b;
end;
wondow1.text := result.toString;
end;
procedure calculator.Exp_Click(sender: Object; e: EventArgs);
begin
wondow1.Text := wondow1.Text + '2.718281828459';
wondow2.Text := wondow2.Text + '2.718281828459';
end;
procedure calculator.Pi_Click(sender: Object; e: EventArgs);
begin
wondow1.Text := wondow1.Text + '3.14159265358979';
wondow2.Text := wondow2.Text + '3.14159265358979';
end;
procedure calculator.Cos_Click(sender: Object; e: EventArgs);
begin
a := real.Parse(wondow1.text);
operation := button(sender).text;
a := (a * pi / 180);
wondow1.text := a.ToString;
end;
procedure calculator.sin_Click(sender: Object; e: EventArgs);
begin
a := real.Parse(wondow1.text);
operation := button(sender).text;
var a := a * pi / 180;
wondow1.text := a.tostring;
end;
procedure calculator.Ln_Click(sender: Object; e: EventArgs);
begin
a := real.Parse(wondow1.text);
operation := button(sender).text;
a := Ln(a) / Ln(2.718281828459);
wondow1.text := a.ToString;
end;
procedure calculator.Lg_Click(sender: Object; e: EventArgs);
begin
a := real.Parse(wondow1.text);
operation := button(sender).text;
a := Ln(a) / Ln(10);
wondow1.text := a.ToString;
end;
procedure calculator.degree_Click(sender: Object; e: EventArgs);
begin
a := real.Parse(wondow1.text);
operation := button(sender).text;
a := a*a;
wondow1.text := a.ToString;
end;
end. |
|
Решил проблему , кроме синуса и косинуса