Upcoming SlideShare
×

# Programas Gambas

555 views

Published on

• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

• Be the first to like this

### Programas Gambas

1. 1. EJERCICIOS “GAMBAS” (BAJO CONSOLA)
2. 2. EJERCICIO 1 “HOLA MUNDO”PUBLIC SUB Main()PRINT "HOLA MUNDOn"PRINT "HOLA MUNDO"END EJERCICIO 2 “SUMA”PUBLIC SUB Main()
3. 3. `Mi primera sumaDIM A AS IntegerDIM B AS IntegerDIM S AS IntegerA = 10B = 20S=A+ BPRINT "LA SUMA ES...:"PRINT SEND EJERCICIO 3 “MAYOR DE 3”‘entre 3 números averiguar cuál es el mayor‘el menor y el intermedio.PUBLIC SUB Main()DIM A, B, C AS IntegerA= 6B = 10C = 80IF A > B AND A > C THEN
4. 4. PRINT "MAYOR ES..: " & AIF C > B THENPRINT "INTERMEDIO ES..: " & CPRINT "MENOR ES..: " & BELSEPRINT "INTERMEDIO ES..: " & BPRINT "MENOR ES..: " & CENDIFELSEIF B > C THENPRINT "MAYOR ES..: " & B IF A > C THENPRINT "INTERMEDIO ES..: " & APRINT "MENOR ES..: " & CELSEPRINT "INTERMEDIO ES..: " & CPRINT "MENOR ES..: " & AENDIFELSEPRINT "MAYOR ES..: " & CIF A > B THENPRINT "INTERMEDIO ES..: " & APRINT "MENOR ES..: " & BELSEPRINT "INTERMEDIO ES..: " & BPRINT "MENOR ES..: " & AENDIFENDIFENDIFEND
5. 5. EJERCICIO 4 “DIGITO AUTOVERIFICADOR”PUBLIC SUB Main()DIM B, C, D, E, F, G, H, I, J, K, W AS IntegerDIM A AS StringPRINT "INGRESE EL NUMERO DE CEDULA"INPUT AFOR B = 1 TO 9 STEP 1C = Str(Mid(A, B, 1))D = B MOD 2IF D = 0 THENI=I+CELSEH=C*2IF H > 9 THEND = H MOD 10E = Int(h / 10)F=D+EELSEF=HENDIFG=G+FENDIF
6. 6. NEXTJ=G+IK = J MOD 10W = 10 - KPRINT "EL NUMERO VERIFICADOR DE LA CEDULA ES : "PRINT WEND EJERCICIO 5 “DE TODO UN POCO”PUBLIC SUB Main()DIM a AS IntegerDIM NOMBRE, C AS StringDIM F, I, X, T AS IntegerPRINT "INGRESE UN NÚMERO..:"INPUT aPRINT "INGRESE UN NOMBRE..:"INPUT NOMBREPRINT "EL NÚMERO QUE INGRESE ES..", aPRINT "EL NOMBRE ES..", NOMBREC = Mid(NOMBRE, 2, 2)PRINT "EL CARACTER SELECCIONADO ES..:", C F=1 FOR I = 1 TO 5 F=F*INEXTPRINT "EL FACTORIAL DE 5 ES..: ", F X=1 WHILE X <= 10 T=2*X PRINT "2 X " & Str(X) & "=" & Str(T) X=X+1 WENDEND
7. 7. EJERCICIO 6 “EXPORTACION”El Ecuador exporta cafe, cacao y maíz en qq, se desea calcular el total de las exportacionesy el porcentaje de cada producto exportado, con los siguientes datosMAIZ 300, CAFE 400, CACAO 800PUBLIC SUB Main()DIM A AS IntegerDIM B AS IntegerDIM C AS IntegerDIM S AS IntegerDIM P1 AS FloatDIM P2 AS FloatDIM P3 AS FloatA = 300B = 400C = 800S=A+ B+ CP1 = A * 100 / SP2 = B * 100 / SP3 = C * 100 / SPRINT "El Total de las exportaciones es..: " & SPRINT "El porcentaje de MAIZ es..: " & P1 & "%"PRINT "El porcentaje de CAFE es..: " & P2 & "%"
8. 8. PRINT "El porcentaje de CACAO es..: " & P3 & "%"END EJERCICIO 7 “FUNCIONES”PROCEDIMIENTO PRINCIPALPUBLIC SUB Main() DIM a, b, h, z AS Integer PRINT "Ingrese un número.:" INPUT a PRINT "Ingrese un número.:" INPUT b pintamedia(a, b) h = 30 z = 70 pintamedia(h, z)ENDPROCEDIMIENTO 1PUBLIC SUB pintamedia(v1 AS Integer, v2 AS Integer) AS Integer DIM s AS Integer s = v1 + v2 PRINT "La suma es..: ", sEND
9. 9. EJERCICIO 8 “PINTAMEDIA”PUBLIC SUB Main() DIM a, b AS Integer PRINT "Ingrese un número.:" INPUT a PRINT "Ingrese un número.:" INPUT b Llamada a función suma, resta, multiplicación y división PRINT "La suma es..: ", suma(a, b) PRINT "La resta es..: ", resta(a, b) PRINT "La multiplicación es..: ", multiplicacion(a, b) PRINT "La división es..: ", division(a, b)ENDFunción sumaPUBLIC SUB suma(v1 AS Integer, v2 AS Integer) AS Integer DIM s AS Integer s = v1 + v2 RETURN sENDFunción restaPUBLIC SUB resta(v1 AS Integer, v2 AS Integer) AS Integer DIM r AS Integer r = v1 - v2 RETURN rENDFunción multiplicaciónPUBLIC SUB multiplicacion(v1 AS Integer, v2 AS Integer) AS Integer DIM m AS Integer
10. 10. m = v1 * v2 RETURN mENDFunción divisiónPUBLIC SUB division(v1 AS Integer, v2 AS Integer) AS Integer DIM d AS Integer d = v1 / v2 RETURN dE EJERCICIO 9 “MODULO FIBONACCI”PUBLIC SUB Main() Serie de Fibonacci DIM p, s, x, t AS Integer DIM fibo AS String p=0 s=1 fibo = Str(p) & " " & Str(s) WHILE x < 5 t=p+s fibo = fibo & " " & Str(t) p=s s=t x=x+1 WEND PRINT fiboEND
11. 11. EJERCICIO 10 “OBJETO SUPERHEROE”PRIVATE Heroe1 AS NEW SUPERHEROEPRIVATE Heroe2 AS NEW SUPERHEROEPUBLIC SUB Main()Heroe1.Nombre = "Superman"Heroe1.Actor = "Ramón Zambrano"Heroe1.Habilidad = "Volar"Heroe1.Imprime()WITH Heroe2 .Nombre = "Batman" .Actor = "Ochoa" .Habilidad = "Visión Nocturna" .ImprimeEND WITHEND
12. 12. EJERCICIO 11 “OBJETO SERES VIVOS”INHERITS SeresVivosPRIVATE Nombre AS StringPRIVATE Apellido AS StringPUBLIC SUB PoneNombre(cadena AS String) Nombre = cadenaENDPUBLIC SUB PoneApellido(cadena AS String) Apellido = cadenaENDPUBLIC FUNCTION Nombrecompleto() AS String RETURN Nombre & " " & ApellidoEND
13. 13. EJERCICIO 12 “OBJETO VEHICULO”PRIVATE marca AS StringPRIVATE modelo AS IntegerPRIVATE precio AS IntegerPRIVATE color AS StringPRIVATE placa AS StringPUBLIC SUB mar(marca1 AS String) marca = marca1ENDPUBLIC SUB model(fecha AS String) modelo = fechaENDPUBLIC SUB pre(valor AS Integer) precio = valorENDPUBLIC SUB col(tinte AS String) color = tinteENDPUBLIC SUB pla(codigo AS String) placa = codigoENDPUBLIC FUNCTION marcaauto() AS String
14. 14. RETURN marcaENDPUBLIC FUNCTION modeloauto() AS String RETURN modeloENDPUBLIC FUNCTION precioauto() AS Integer RETURN precioENDPUBLIC FUNCTION colorauto() AS String RETURN colorENDPUBLIC FUNCTION placaauto() AS String RETURN placaEND EJERCICIOS “GAMBAS” (APLICACIÓN GRAFICA) EJERCICIO 13 “OPERACIONES BÁSICAS”PUBLIC SUB Button1_Click() suma.text = Val(num1.text) + Val(num2.text) resta.text = num1.text - num2.text multi.text = num1.text * num2.text divi.text = num1.text / num2.textENDPUBLIC SUB Button2_Click() num1.text = "" num2.text = "" suma.text = ""
15. 15. resta.text = "" multi.text = "" divi.text = ""ENDPUBLIC SUB Button3_Click() ME.CloseEND EJERCICIO 14 “VENTANA”PUBLIC SUB Main()DIM vent AS windowvent = NEW windowvent.show()END
16. 16. EJERCICIO 15 “MENU”PUBLIC SUB Timer1_Timer()segundos.text = Val(segundos.Text) + 1 IF segundos.text = 59 THEN minutos.text = Val(minutos.text) + 1 segundos.text = "0" segundos.text = Val(segundos.text) + 1 ELSE IF minutos.text = 59 THEN horas.text = Val(horas.text) + 1 minutos.text = "0" ENDIF ENDIFENDPUBLIC SUB Button1_Click() IF Button1.text = "Iniciar" THEN Timer1.enabled = TRUE Button1.caption = "Parar"
17. 17. ELSE Timer1.Enabled = FALSE Button1.text = "Iniciar" ENDIFENDPUBLIC SUB Button2_Click() segundos.text = "0" minutos.text = "0" horas.text = "0"END EJERCICIO 16 “JUEGO”PUBLIC SUB Button1_Click() DIM n1, n2, n3 AS Integer RANDOMIZE n1 = Int(Rnd() * 10) n2 = Int(Rnd() * 10) n3 = Int(Rnd() * 10) TextBox1.Text = n1 TextBox2.Text = n2 TextBox3.Text = n3 IF n1 = n2 AND n1 = n3 THEN Message("GANASTES") TextBox5.Text = TextBox4.Text * 2 ELSE IF n1 = 7 AND n2 = 7 AND n3 = 7 THEN Message("CONGRATULATIONS GANASTES EL PREMIO MAYOR") TextBox5.Text = TextBox4.Text * 4
18. 18. ENDIF ENDIFENDPUBLIC SUB Button2_Click() ME.CloseEND EJERCICIO 17 “GRÁFICOS”PUBLIC r AS IntegerPUBLIC posy AS IntegerPUBLIC posx AS IntegerPUBLIC al AS IntegerPUBLIC ba AS IntegerPUBLIC SUB Form_Open()r = 20ENDPUBLIC SUB Button1_Click() posy = area1.Height / 2 posx = area1.Width / 2 Draw.Begin(area1) Draw.FillColor = Color.RGB(128, 255, 0)
19. 19. Draw.FillStyle = Fill.Solid Draw.Circle(posx, posy, r) r = r + 20 Draw.Ellipse(200, 200, 100, 50) Draw.EndENDPUBLIC SUB Button3_Click() ME.CloseENDPUBLIC SUB Button2_Click() area1.Clear posy = area1.Height / 2 posx = area1.Width / 2 Draw.Begin(area1) Draw.FillColor = Color.RGB(128, 255, 0) Draw.FillStyle = Fill.Solid Draw.Circle(posx, posy, r) r = r - 20 Draw.Ellipse(200, 200, 100, 50) Draw.EndENDPUBLIC SUB Button4_Click() area1.Clear Draw.Begin(area1) posy = area1.Height / 2 posx = area1.Width / 2 Draw.FillColor = Color.RGB(255, 223, 117) Draw.FillStyle = Fill.Solid Draw.Rect(posx, posy, al, ba) Draw.End al = al + 10 ba = ba + 10END EJERCICIO 18 “PROTECTOR DE PANTALLA”PUBLIC C1 AS IntegerPUBLIC C2 AS IntegerPUBLIC C AS IntegerPUBLIC r AS IntegerPUBLIC SUB Button1_Click() IF Button1.Text = "Iniciar Fondo" THEN Timer1.Enabled = TRUE Button1.Caption = "Parar" ELSE Timer1.Enabled = FALSE Button1.Text = "Iniciar Fondo" ENDIFENDPUBLIC SUB Button2_Click() ME.CloseEND
20. 20. PUBLIC SUB Timer1_Timer() C1 = Int(Rnd() * 700) C2 = Int(Rnd() * 700) C = Int(Rnd() * 15) Draw.Begin(area1) Draw.FillColor = Color.RGB((160 + c1), (2 + c2), (c1 + C2)) coge los colores que se designen Draw.FillStyle = Fill.Solid Draw.Circle(C1, C2, C) Draw.EndEND EJERCICIO 19 “CALCULADORA”PUBLIC BAN AS IntegerPUBLIC OP1 AS FloatPUBLIC OP2 AS FloatPUBLIC SUB Button10_Click() visor.text = visor.Text & "0"ENDPUBLIC SUB Button11_Click() visor.text = visor.Text & "."ENDPUBLIC SUB Button7_Click() visor.text = visor.Text & "1"ENDPUBLIC SUB Button8_Click() visor.text = visor.Text & "2"ENDPUBLIC SUB Button9_Click() visor.text = visor.Text & "3"
21. 21. ENDPUBLIC SUB Button4_Click() visor.text = visor.Text & "4"ENDPUBLIC SUB Button5_Click() visor.text = visor.Text & "5"ENDPUBLIC SUB Button6_Click() visor.text = visor.Text & "6"ENDPUBLIC SUB Button1_Click() visor.text = visor.Text & "7"ENDPUBLIC SUB Button2_Click() visor.text = visor.Text & "8"ENDPUBLIC SUB Button3_Click() visor.text = visor.Text & "9"ENDPUBLIC SUB Button12_Click() ME.CloseENDPUBLIC SUB Button16_Click() visor.text = ""ENDPUBLIC FUNCTION operacion(v1 AS Float, v2 AS Float, opera AS Integer) AS FloatDIM re AS Float SELECT CASE opera CASE 1 re = v1 + v2 CASE 2 re = v1 - v2 CASE 3 re = v1 * v2 CASE 4 re = v1 / v2 CASE 5 re = (v1 * v2) / 100 CASE 6 re = v1 ^ 2 CASE 7 re = v1 ^ 3 CASE 8 re = v1 ^ v2 CASE 9 re = 1 / v1 END SELECT RETURN reENDPUBLIC SUB Button13_Click() BAN = 1 IF visor.text <> 0 THEN OP1 = visor.Text ELSE OP1 = 0 ENDIF visor.ClearENDPUBLIC SUB Button14_Click() BAN = 2 IF visor.text <> 0 THEN OP1 = visor.Text ELSE
22. 22. OP1 = 0 ENDIF visor.ClearENDPUBLIC SUB Button18_Click() BAN = 3 IF visor.text <> 0 THEN OP1 = visor.Text ELSE OP1 = 0 ENDIF visor.ClearENDPUBLIC SUB Button17_Click() BAN = 4 IF visor.text <> 0 THEN OP1 = visor.Text ELSE OP1 = 0 ENDIF visor.ClearENDPUBLIC SUB Button15_Click() IF visor.text <> 0 THEN OP2 = visor.Text ELSE OP2 = 0 ENDIF visor.Text = operacion(OP1, OP2, BAN)ENDPUBLIC SUB Button19_Click() BAN = 5 IF visor.text <> 0 THEN OP1 = visor.Text ELSE OP1 = 0 ENDIF visor.ClearENDPUBLIC SUB Button20_Click() BAN = 6 IF visor.text <> 0 THEN OP1 = visor.Text ELSE OP1 = 0 ENDIF visor.text = OP1ENDPUBLIC SUB Button21_Click() DIM valor, x1, x2, i AS Integer DIM cadena, cadena2 AS String valor = visor.Text WHILE valor > 0 x1 = valor MOD 2 x2 = Int(valor / 2) cadena = cadena & Str(x1) valor = x2 WEND FOR i = Len(cadena) TO 1 STEP -1 cadena2 = cadena2 & (Mid(cadena, i, 1)) NEXT visor.text = cadena2END