You are on page 1of 10

CALCULADORA DE CONJUNTOS

Código de programación:

Option Base 1
Dim A(50) As String
Dim B(50) As String
Dim C(50) As String
Dim cA As Integer
Dim cB As Integer
Dim cC As Integer
Dim codigo As Integer
Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim existe As Boolean

Private Sub CmdCardinalidad_Click()


cB = Val(TxtPantalla.Text)
TxtPantalla.Text = ""
TxtPantalla.SetFocus
k=1
CmdElemento.Caption = "Elemento" & k
End Sub

Private Sub CmdCartesiano_Click()


TxtPantalla.Text = ""
TxtPantalla.SetFocus
cA = cB
For i = 1 To cA
A(i) = B(i)
Next i
codigo = 5
End Sub

Private Sub CmdDiferencia_Click()


TxtPantalla.Text = ""
TxtPantalla.SetFocus
cA = cB
For i = 1 To cA
A(i) = B(i)
Next i
codigo = 3
End Sub

Private Sub CmdElemento_Click()


B(k) = TxtPantalla.Text
k=k+1
CmdElemento.Caption = "Elemento" & k
TxtPantalla.Text = ""
TxtPantalla.SetFocus

If k > cB Then
CmdElemento.Caption = "Elemento i"
TxtPantalla.Text = " { "
For i = 1 To cB - 1
TxtPantalla.Text = TxtPantalla.Text & B(i) & ","
Next i
TxtPantalla.Text = TxtPantalla.Text & B(cB) & " } "
End If

End Sub

Private Sub CmdIgual_Click()


Select Case codigo
Case 1
k = cB
For i = 1 To cA
existe = False
For j = 1 To cB
If A(i) = B(j) Then
existe = True

End If
Next j
If Not existe Then
k=k+1
B(k) = A(i)

End If
Next i
cB = k

Case 2
k=0
For i = 1 To cA
existe = False
For j = 1 To cB
If A(i) = B(j) Then
existe = True

End If
Next j
If existe Then
k=k+1
B(k) = A(i)
End If
Next i
cB = k

Case 3
cC = 0
For i = 1 To cA
existe = False
For j = 1 To cB
If A(i) = B(j) Then
existe = True

End If
Next j
If Not existe Then
cC = cC + 1
C(cC) = A(i)

End If
Next i
cB = cC
For i = 1 To cB
B(i) = C(i)
Next i

Case 4
k = cA
For i = 1 To cB
existe = False
For j = 1 To cA
If B(i) = A(j) Then
existe = True
A(j) = ""
End If
Next j
If Not existe Then
A(k) = B(i)
k=k+1
End If
Next i
cB = 0
For i = 1 To k
If A(i) <> "" Then
cB = cB + 1
B(cB) = A(i)
End If
Next i
Case 5
cC = 0
For i = 1 To cA
For j = 1 To cB
cC = cC + 1
C(cC) = "(" & A(i) & "," & B(j) & ")"
Next j
Next i
cB = cC
For i = 1 To cB
B(i) = C(i)
Next i

End Select
TxtPantalla.Text = " { "
For i = 1 To cB - 1
TxtPantalla.Text = TxtPantalla.Text & B(i) & ","
Next i
TxtPantalla.Text = TxtPantalla.Text & B(cB) & " } "

End Sub
Private Sub CmdInter_Click()
TxtPantalla.Text = ""
TxtPantalla.SetFocus
cA = cB
For i = 1 To cA
A(i) = B(i)
Next i
codigo = 2
End Sub

Private Sub CmdSimetrica_Click()


TxtPantalla.Text = ""
TxtPantalla.SetFocus
cA = cB
For i = 1 To cA
A(i) = B(i)
Next i
codigo = 4
End Sub

Private Sub CmdUnion_Click()


TxtPantalla.Text = ""
TxtPantalla.SetFocus
cA = cB
For i = 1 To cA
A(i) = B(i)
Next i
codigo = 1
End Sub
CALCULADORA DE POLINOMIOS

Código de programación:
Dim grado2 As Integer
Dim b(40) As Single
Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim valx As Single
Dim polx As Single
Dim grado1 As Integer
Dim a(40) As Single
Dim grado As Integer
Dim c(50) As Single
Dim codigo As Integer

Private Sub CmdCoeficiente_Click()


b(k) = CSng(TxtPantalla.Text)
TxtPantalla.Text = ""
TxtPantalla.SetFocus
k=k-1
CmdCoeficiente.Caption = "Coeficiente x^" & k
If k < 0 Then
CmdCoeficiente.Caption = "Coeficiente x^i"
TxtPantalla.Text = b(grado2) & "x^" & grado2
For i = grado2 - 1 To 1 Step -1
If b(i) > 0 Then
TxtPantalla.Text = TxtPantalla.Text & " + " & b(i) & "x^" & i
ElseIf b(i) < 0 Then
TxtPantalla.Text = TxtPantalla.Text & " " & b(i) & "x^" & i
End If
Next i
TxtPantalla.Text = TxtPantalla.Text & " + " & b(0)
End If
End Sub

Private Sub CmdEvaluar_Click()


valx = CSng(TxtPantalla.Text)
polx = 0
For i = o To grado2
polx = polx + b(i) * valx ^ i
Next i
TxtPantalla.Text = "P(" & valx & ")= " & polx
End Sub

Private Sub CmdGrado_Click()


grado2 = Val(TxtPantalla.Text)
k = grado2
CmdCoeficiente.Caption = "Coeficiente x^" & k
TxtPantalla.Text = ""
TxtPantalla.SetFocus
End Sub

Private Sub CmdIgual_Click()


Select Case codigo
Case 1:
For i = 0 To grado1
b(i) = b(i) + a(i)
Next i
If grado1 > grado2 Then
grado2 = grado1
End If
Case 2:
For i = 0 To grado1
b(i) = b(i) - a(i)
Next i
If grado1 > grado2 Then
grado2 = grado1
End If
Case 3:
For i = 0 To grado1
For j = 0 To grado2
k=i+j
c(k) = c(k) + a(i) * b(j)
Next j
Next i
k=i+j
For grado2 = 0 To k
b(grado2) = c(grado2)
Next grado2
grado2 = k
End Select
TxtPantalla.Text = b(grado) & "x^" & grado2
For i = grado2 - 1 To 1 Step -1
If b(i) > 0 Then
TxtPantalla.Text = TxtPantalla.Text & " + " & b(i) & "x^" & i
ElseIf b(i) < 0 Then
TxtPantalla.Text = TxtPantalla.Text & " " & b(i) & "x^" & i
End If
Next i
TxtPantalla.Text = TxtPantalla.Text & " + " & b(0)
End Sub

Private Sub CmdLimpiar_Click()


TxtPantalla.Text = ""
TxtPantalla.SetFocus
End Sub

Private Sub CmdMas_Click()


codigo = 1
grado1 = grado2
For i = 0 To grado1
a(i) = b(i)
Next i
TxtPantalla.Text = ""
TxtPantalla.SetFocus
End Sub

Private Sub CmdMenos_Click()


codigo = 2
grado1 = grado2
For i = 0 To grado1
a(i) = b(i)
Next i
TxtPantalla.Text = ""
TxtPantalla.SetFocus
End Sub

Private Sub CmdPor_Click()


codigo = 3
grado1 = grado2
For i = 0 To grado1
a(i) = b(i)
Next i
TxtPantalla.Text = ""
TxtPantalla.SetFocus
End Sub

Private Sub CmsSalir_Click()


End
End Sub