-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFrmMatricesUnit2.pas
153 lines (136 loc) · 3.95 KB
/
FrmMatricesUnit2.pas
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
unit FrmMatricesUnit2;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;
type
TFrmMatrices = class(TForm)
GenerarButton: TButton;
MatricesListBox: TListBox;
SumaButton: TButton;
RestaButton: TButton;
DivisionButton: TButton;
MultiplicacionButton: TButton;
ResultadoListBox: TListBox;
procedure GenerarButtonClick(Sender: TObject);
procedure ProcesarOperacion(op:Integer);
procedure SumaButtonClick(Sender: TObject);
procedure RestaButtonClick(Sender: TObject);
procedure DivisionButtonClick(Sender: TObject);
procedure MultiplicacionButtonClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
const
SUMA = 1;
RESTA = 2;
DIVISION = 3;
MULTIPLICACION = 4;
var
FrmMatrices: TFrmMatrices;
matrice : Array[1..3,1..3] of integer;
implementation
{$R *.dfm}
procedure TFrmMatrices.ProcesarOperacion(op:Integer);
var
x: Integer;
I:integer;
result:Extended;
display:string;
begin
ResultadoListBox.Clear;
case op of
1: //SUMA
begin
for I := 1 to 3 do
begin
//FILA Y COLUMNA
result:= matrice[1,I] + matrice[2,I] + matrice[3,I];
display := IntToStr(matrice[1,I]) +
' + ' + IntToStr(matrice[2,I]) +
' + ' + IntToStr(matrice[3,I]) +
' = ' + FloatToStr(result);
ResultadoListBox.Items.Add(display)
end;
end;
2: //RESTA
begin
for I := 1 to 3 do
begin
//FILA Y COLUMNA
result:= (matrice[1,I] - matrice[2,I]) - matrice[3,I];
display := IntToStr(matrice[1,I]) +
' - ' + IntToStr(matrice[2,I]) +
' - ' + IntToStr(matrice[3,I]) +
' = ' + FloatToStr(result);
ResultadoListBox.Items.Add(display)
end;
end;
3: //DIVISION
begin
for I := 1 to 3 do
begin
//FILA Y COLUMNA
result:= (matrice[1,I] / matrice[2,I]) / matrice[3,I];
display := IntToStr(matrice[1,I]) +
' / ' + IntToStr(matrice[2,I]) +
' / ' + IntToStr(matrice[3,I]) +
' = ' + FloatToStr(result);
ResultadoListBox.Items.Add(display)
end;
end;
4: //MULTIPLICACION
begin
for I := 1 to 3 do
begin
//FILA Y COLUMNA
result:= (matrice[1,I] * matrice[2,I]) * matrice[3,I];
display := IntToStr(matrice[1,I]) +
' x ' + IntToStr(matrice[2,I]) +
' x ' + IntToStr(matrice[3,I]) +
' = ' + FloatToStr(result);
ResultadoListBox.Items.Add(display)
end;
end;
end;
end;
procedure TFrmMatrices.RestaButtonClick(Sender: TObject);
begin
ProcesarOperacion(RESTA);
end;
procedure TFrmMatrices.SumaButtonClick(Sender: TObject);
begin
ProcesarOperacion(SUMA);
end;
procedure TFrmMatrices.DivisionButtonClick(Sender: TObject);
begin
ProcesarOperacion(DIVISION);
end;
procedure TFrmMatrices.GenerarButtonClick(Sender: TObject);
var
x: Integer;
I:integer;
msg1:string;
value:string;
begin
MatricesListBox.Clear;
ResultadoListBox.Clear;
for I := 1 to 3 do
begin
for x := 1 to 3 do
begin
msg1 := 'Posicion de la matrix ' + IntToStr(I) +
' x ' + IntToStr(x);
value := InputBox(msg1,'Ingrese un numero valido','');
matrice[I,x] := StrToInt(value);
MatricesListBox.Items.Add(IntToStr(I) + ',' + IntToStr(x) + ' :: ' + value);
end;
end;
end;
procedure TFrmMatrices.MultiplicacionButtonClick(Sender: TObject);
begin
ProcesarOperacion(MULTIPLICACION);
end;
end.