Olá, gostaria de resolver os cálculos da álgebra de boole de forma simples e fácil, pois bem, eu usando a programação orientada a objetos eu fiz uma simples aplicação que calcula a álgebra de boole! Confira logo abaixo.
CLASSE ALGEBRA
Public Class algebra
Private _a As String
Private _b As String
Private _c As String
Public Property a() As String
Get
Return _a
End Get
Set(ByVal value As String)
_a = value
End Set
End Property
Public Property b() As String
Get
Return _b
End Get
Set(ByVal value As String)
_b = value
End Set
End Property
Public Property c() As String
Get
Return _c
End Get
Set(ByVal value As String)
_c = value
End Set
End Property
Public Function calcula() As Integer
If (b = "And") Then
If (a = 1) And (c = 1) Then
calcula = 1
Else
calcula = 0
End If
End If
If (b = "Or") Then
If (a = 0) And (c = 0) Then
calcula = 0
Else
calcula = 1
End If
End If
Return calcula
End Function
End Class
FORMULÁRIO
Public Class Form1
Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click
Dim a As New algebra
If (Label1.Text = 0) Then
Label1.Text = 1
Else
Label1.Text = 0
End If
a.a = Label1.Text
a.b = Label2.Text
a.c = Label3.Text
Label5.Text = a.calcula()
End Sub
Private Sub Label2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label2.Click
Dim a As New algebra
If (Label2.Text = "And") Then
Label2.Text = "Or"
Else
Label2.Text = "And"
End If
a.a = Label1.Text
a.b = Label2.Text
a.c = Label3.Text
Label5.Text = a.calcula()
End Sub
Private Sub Label3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label3.Click
Dim a As New algebra
If (Label3.Text = 1) Then
Label3.Text = 0
Else
Label3.Text = 1
End If
a.a = Label1.Text
a.b = Label2.Text
a.c = Label3.Text
Label5.Text = a.calcula()
End Sub
End Class
Espero ter ajudado e até a próxima. =)
0 comentários:
Postar um comentário