Abel Gutirrez Barn Ricardo Gutirrez Trinidad Alejandra Salinas Castillo
El programa utilizado para crear la calculadora de nmeros complejos es visual basic, escogimos este por si fcil uso para interfaz grafica y as poder crear mejor un sistema donde pudiramos observar de manera correcta cada valor obtenido.
Primero mostraremos el cdigo e iremos explicando poco a poco para que funciona cada una de las partes de este cdigo, as como unas imgenes del programa ya terminado y funcionando. En esta parte del cdigo es usada para las variables. Dim a As Integer Dim b As Integer Dim c As Integer Dim d As Integer Dim z, t As Integer Dim s, r, rr, m, di, div, num, p, q, mul As Integer Dim at1, at2, vab, vcd, raiz, u As Integer Dim X, Y As Integer Como vemos aqu esta es la parte del cdigo donde tomamos los valores ingresados y los asignamos a una variable, a, b, c, d.
Private Sub Command9_Click() 'Tomar valores a = Text1 b = Text2 c = Text3 d = Text4 raiz = 2 En esta parte es donde se hace la primera formula la suma.
'Z1+Z2 s = b + d If s < 0 Then TRS1 = "-" TRI1 = s * -1 Else If s > 0 Then TRS1 = "+" TRI1 = s End If End If TRR1 = a + c iuno = "i"
Aqui es donde se muestra la operacion de resta. 'Z1-Z2 r = b - d If r < 0 Then TRS2 = "-" TRI2 = r * -1 Else If r > 0 Then TRS2 = "+" TRI2 = r End If End If TRR2 = a - c idos = "i" 'Z2-Z1 r = a - c If r < 0 Then TRS3 = "-" TRI3 = r * -1 Else If r > 0 Then TRS3 = "+" TRI3 = r End If End If TRR3 = b - d itres = "i"
Aqui es donde se muestra la operacion de multiplicacion. 'Z1*Z2 m = (a * d + b * c) If m > 0 Then TRS4 = "+" mul = m End If If m < 0 Then TRS4 = "-" mul = m * -1 End If TRR4 = ((a * c) - (b * d)) TRI4 = mul icuatro = "i" Esta es la parte de la divicion donde se hacen mas operaciones y donde tiene que ser Z2 diferente de 0 para que pueda ser valida de lo contrario marcara error. 'Z1/Z2 If d = 0 Then 'Label1.Visible = True Error.Visible = True End If If d <> 0 Then Error.Visible = False div = ((c ^ 2) + (d * d)) p = ((b * c) - (a * d)) q = ((a * c) + (b * d)) If p > 0 Then TRI51 = p TRS5 = "+" Else If p < 0 Then TRI51 = (p * -1) TRS5 = "-" End If End If
If q > 0 Then TRR51 = q TRS51 = "+" Else If q < 0 Then TRR51 = (q * -1) TRS51 = "-" End If End If TRR52 = div TRI52 = div icinco = "i" End If
'Z1* If b > 0 Then TRS6 = "-" TRI6 = b Else If b < 0 Then TRI6 = b * -1 TRS6 = "+" End If End If TRR6 = a iseis = "i
'Z2* If d > 0 Then TRS7 = "-" TRI7 = d Else If d < 0 Then TRI7 = d * -1 TRS7 = "+" End If End If TRR7 = c isiete = "i" En esta parte es donde ya convertimos a polar los datos ingresados 'Forma polar z1 vad = (a ^ 2) + (b ^ 2) z = vad ^ (1 / raiz)
'condiciones para a diferente a 0 If a <> 0 Then t = b / a Text = t Tanin = Atn(t) 'condiciones para a y b positivo If a And b > 0 Then Resul = Atn(t) End If
'condiciones para a y b negativo If a And b < 0 Then Resul = (180 - Atn(t)) End If
'condiciones para a negativo y b positivo If a < 0 And b > 0 Then Resul = (180 + Atn(t)) End If
'condiciones para a positivo y b negativo If a > 0 And b < 0 Then Resul = (360 - Atn(t)) End If
'condiciones para a positivo y b igual a 0 If a > 0 And b = 0 Then Resul = (0) End If 'condiciones para a negativo y b igual a 0 If a < 0 And b = 0 Then Resul = (180) End If End If
If a = 0 Then 'condiciones para b positivo If b > 0 Then Resul = (90) End If
'condiciones para a negativo y b igual a 0 If b < 0 Then Resul = (270) End If End If lbgrad = "" Cis = "Cis" TRR81 = z TRI81 = Resul
Como se ve aqu se usan muchas condiciones iniciales donde depende de cuanto valen los datos si son menor a 0 mayor a 0 o si es igual.
'Forma polar z2 vad = (c ^ 2) + (d ^ 2) z = vad ^ (1 / raiz)
'condiciones para c diferente a 0 If c <> 0 Then u = d / c Textdos = u Tanindos = Atn(u)
'condiciones para c y d positivo If c And d > 0 Then Resuldos = Atn(u) End If
'condiciones para c y d negativo If c And d < 0 Then Resuldos = (180 - Atn(u)) End If
'condiciones para a negativo y b positivo If c < 0 And d > 0 Then Resuldos = (180 + Atn(u)) End If
'condiciones para c positivo y d negativo If c > 0 And d < 0 Then Resuldos = (360 - Atn(u)) End If
'condiciones para c positivo y d igual a 0 If c > 0 And d = 0 Then Resuldos = (0) End If
'condiciones para c negativo y d igual a 0 If c < 0 And d = 0 Then Resuldos = (180) End If End If
If a = 0 Then 'condiciones para d positivo If d > 0 Then Resuldos = (90) End If
'condiciones para a negativo y d igual a 0 If d < 0 Then Resuldos = (270) End If End If lbgraddos = "" Cisdos = "Cis" TRR91 = z
Igual que en el anterior aqui se usan los if donde define de cuanto vale cada valor que se ingreso. Aqu la multiplicacin y la divisin de polares. 'Multiplicacin polares TRR10 = TRR81 * TRR91 TRI10 = Resul + Resuldos lbgradtres = "" Cistres = "Cis"
End Sub Private Sub Convertir_Click() 'Tomar valores X = Text5 Y = Text6 C1 = Cos(Y) S1 = Sin(Y) TRR12 = X * C1 RS1 = X * S1 If RS1 > 0 Then TRI12 = (RS1) End If 'condiciones para a negativo y d igual a 0 If RS1 < 0 Then TRI12 = (RS1 * (-1)) End If MA1 = "+" ME1 = "-" If S1 > 0 Then TRS12 = (MA1) End If 'condiciones para a negativo y d igual a 0 If S1 < 0 Then TRS12 = (ME1) End If
End Sub
Como vimos es relativamente fcil hacer esto son solo el uso de formulas ya designadas que se usan en el programa, ese es el cdigo y aqu pueden ver las imgenes del programa ya funcionando.