La empresa sostenible: Principales Características, Barreras para su Avance y...
ejercios de gambas
1. Unidad educativa “Hugo cruz Andrade”
Datos personales
Nombre:
Bryan Fabián
Materia:
D.F.S.I
Ing.:
STALIN RODRIGEZ
Año lectivo:
2015-2016
2. INDICE
Contenido
1. Programa que muestre el nombre ylosapellidosde unapersona................................................................................2
2. Cadenade texto, realizadaenconsola...........................................................................................................................2
3. Programa enconsolapara sacar enpromediode 3 notas.............................................................................................2
4. Ejecicioparamostrar lamultiplicacióndivisiónsumayrestade dos numeros.............................................................3
5. Exportacionesenel ecuadorexportacafé, cacaoymaíz enquintalesse deseacalcularel total de portacionesyel
porcntaje de cada uno.Productosexportradosconlossiguientesdatos:maíz300, café 400, cacao 800............................3
6. Programa que me permitacalcularel ivade unproducto.............................................................................................4
7. Programa que calcule el áreade untrianguloteniendocomodatosde entradalabase y la altura.............................4
8. Programa que permitarecibircomodatode entradaunadistanciamedidaenmetrosyconvertirlaakilometros..... 4
9. Programa para resolvamoslasiguiente ecuacióny= x3
– x2
+2 - 3”...............................................................................5
10. Opresionesbásicasde matemáticas...........................................................................................................................5
11. La sumade dos valores...............................................................................................................................................5
12. Programaque permite leerlacantidadyel preciode unproductoel mismoque tiene undescuentode 5%
mostrar porpantallael preciototal........................................................................................................................................6
13. Programaque calculael salariode un trabajadorque gana 5 dólaresporhora y trabaja8 horas diarias................6
14. En un aulade clase hay42 alumnosque estadivididoen30mujeresy12 varonescalcularel porcentaje..............7
15. Programaque permite ingresarel valorde unproducto, yel númerode unidadesdelmismo,mostrarpor
Pantallael total de importaciones,ytambiénque muestre lacomisióndel15% enconsola...............................................7
16. Selectcase...................................................................................................................................................................8
17. Ejemplos:.....................................................................................................................................................................9
18. SENTENCIA IF.............................................................................................................................................................11
19. Definircuál valoresmayor.......................................................................................................................................11
20. Forma de pago:1. 2, o 3. ...........................................................................................................................................12
21. Definirel valorde unnumero:..................................................................................................................................13
22. SENTENCIA FOR.........................................................................................................................................................14
23. Ejercicios:..................................................................................................................................................................15
24. Realizaunprogramautilizandolasentenciaforparamostrar10 veceslapalabra“AMISTAD”..............................15
25. REALIZARUNA APLICACIÓNQUEMUESTRE LOS MULTIPLOS DE 3 HASTA EL 99. ....................................................15
26. EJERCICIOSDE CONSOLA ..........................................................................................................................................16
27. AHORA EMPESAREMOS A CREARLA INTERFAZGRAFICA DE NUESTRA APLICACIÓNCON LASHERRAMIENTASQUE
POSEE GAMBASY PODEREDITAR SUS PROPIEDADES..........................................................................................................19
28. EJERCICIO:.................................................................................................................................................................19
29. CALCULADORA BASICA:............................................................................................................................................19
3. 30. APLICACIÓN PARA LA EDAD:.....................................................................................................................................21
4. 31. PARO IMPAR:............................................................................................................................................................23
1. Programa que muestreel nombrey los apellidos de una persona
2. Cadenade texto, realizada en consola
1 PUBLIC SUB Main ( )
2
3 DIM Institucion AS String
4 DIM Pais AS String
5 DIM Provincia AS String
6 DIM Canton AS String
7 Institucion = “UNIDAD EDUCATIVA HUGO CRUZ ANDRADE”
8 Pais = “Ecuador”
9 Provincia = “Manabi”
10 Canton = “El Carmen”
11 PRINT Institucion
12 PRINT Canton & “-” & Provincia & “-” & Pais
13
14 END
3. Programa en consola para sacar en promedio de 3 notas
1 PUBLIC SUB Main ( )
2
3 DIM NT1 AS Single
4 DIM NT2 AS Single
5 DIM NT3 AS Single
6 DIM suma AS Single
7 DIM promedio AS Single
8 PRINT “ingrese la primer nota”
9 INPUT NT1
10 PRINT “ingrese la segunda nota”
11 INPUT NT2
12 PRINT “ingrese la tercer nota”
13 INPUT NT3
14 suma = NT1 + NT1 + NT1
15 Promedio = suma / 3
16 Provincia = “manuel”
17 Canton = “Alvares Gomes”
18 PRINT “ la suma total de las tres notas es:” & suma
5. 19 PRINT “ el promedios es igual a:” & promedio
20
21 END
4. Ejecicio para mostrar la multiplicación división sumay resta de dos numeros
PUBLIC SUB Main ( )
DIM numero1 AS Integer
DIM numero2 AS Integer
DIM suma AS Integer
DIM resta AS Integer
DIM divicion AS Integer
DIM multiplicación AS Integer
numero1 = 30
numero2 = 12
suma = numero1 + numero2 resta =
numero1 - numero2 multiplicacion =
numero1 * numero2 divicion =
numero1 / numero2
PRINT “la suma total de las tres notas es:”&
END
5. Exportaciones en el ecuador exporta café, cacao y maíz en quintales se desea
calcular el total de portaciones y el porcntaje de cada uno. Productos
exportrados con los siguientes datos: maíz 300, café 400, cacao 800
1 PUBLIC SUB Main ()
2 DIM Cacao AS Integer
3 DIM Cafe AS Integer
4 DIM Maiz AS Integer
5 DIM P1 AS Single
6 DIM P2 AS Single
7 DIM Suma AS Integer
8 Café = 400
9 Cacao = 800
10 Maíz = 300
11 Suma = Café + Cacao + Maíz
12 P1 = (Café / Suma ) * 100
13 P2 = (Cacao / Suma ) * 100
14 P3 = (Maíz / Suma ) * 100
15 PRINT “el total de exportaciones es : ” & Suma
16 PRINT “el procentaje del cafe es : ” & P1 & “ % ”
17 PRINT “el procentaje del Cacao es : ” & P2 & “ % ”
18 PRINT “el procentaje del Maíz es : ” & P3 & “ % ”
19 END
6. 6. Programa que me permitacalcular el iva de un producto
1 PUBLIC SUB Main ()
2 DIM NPRO AS String
3 DIM VALOR AS Single
4 DIM iva AS Single
5 DIM cosfn AS Single
6 PRINT “ingrese el nombre de su producto : ”
7 IMPUT NPRO
8 PRINT “ingrese el valor de su producto : ”
9 INPUT VALOR
10 iva = ( VALOR / 100 ) * 12
11 cosfn = 800
12 Maíz = 300
13 Suma = Café + Cacao + Maíz
14 P1 = (Café / Suma ) * 100
15 P2 = (Cacao / Suma ) * 100
16 P3 = (Maíz / Suma ) * 100
17
18 PRINT “el procentaje del Cacao es : ” & P2 & “ % ”
19 PRINT “el procentaje del Maíz es : ” & P3 & “ % ”
20 END
7. Programa que calcule el área de un triangulo teniendo como datos de entrada
la basey la altura
1 PUBLIC SUB main ()
2 DIM Base AS Single
3 DIM Altura AS Single
4 DIM Area AS Single
5 PRINT “ ingrese el altura del triangulo que desea calcular el area ”
6 INPUT Altura
7 PRINT “ingrese la base del triangulo que desea calcular la el area ”
8 INPUT Base
9 Area = (Altura * Base ) / 2
10 Total = (Valor * 12 ) / 100
11 PRINT “el área de triangulo es : ” & Area
12 END
8. Programa que permita recibir como dato de entrada una distancia medidaen
metros y convertirla a kilometros
1 PUBLIC SUB main ( )
2 DIM METRO AS Single
3 DIM Kilometro AS Single
7. 4 PRINT “ ingrese la medida en metros para convertirla a kilometros ”
5 INPUT Metro
6 Kilometro = Metro / 1000
7 PRINT “la medida en km es : ” & Kilometro
8 END
9. Programa para resolvamos la siguiente ecuación y = x3
– x2
+2 - 3”
1 PUBLIC SUB main ( )
2 DIM x AS Byte
3 DIM y AS Single
4 PRINT “ resolvamos la siguiente ecuación y = x3 – x2 +2 - 3”
5 PRINT “se le da el valor a x”
6 INPUT x
7 y = x ^ 3 – x ^ 2 + 2 – 3
8 PRINT “el resultado de la ecuación es : ” & y
9 END
10.Opresiones básicas dematemáticas
1 PUBLIC SUB Main ()
2 DIM B AS Byte
3 DIM C AS Byte
4 B = 20
5 C = 65
6 PRINT B + C
7 PRINT B – C
8 PRINT B / C
9 PRINT B * C
10 END
11. La sumade dos valores
1 PUBLIC SUB main ( )
2 DIM A AS Byte
3 DIM B AS Byte
4 DIM S AS Byte
5 A = 20
6 B = 65
7 S = A +B
8 PRINT “la suma es : ” & S
9 END
8. 12.Programa que permite leer la cantidad y el precio de un productoel mismo
que tiene un descuento de 5% mostrar por pantalla el precio total
1 PUBLIC SUB main ( )
2 DIM Cantidad AS Single
3 DIM Precio AS Single
4 DIM Sud AS Single
5 DIM Des AS Single
6 DIM Prt AS Single
7 DIM Producto AS String
8 PRINT “bienvenido a mi programa”
9 PRINT “ingrese el nombre del producto”
10 INPUT Producto
11 PRINT “ingrese la cantidad del producto”
12 INPUT Cantidad
13 PRINT “ingrese el precio del producto”
14 INPUT Precio
15 Sud = Cantidad * Precio
16 Des = Sud * 0.05
17 Prt = Prt – Des
18 PRINT “el precio total de producto será ”
19 PRINT Prt
20 END
13.Programa que calcula el salario de un trabajador que gana 5 dolares por hora y
trabaja 8 horas diarias
1 PUBLIC SUB main ( )
2 DIM Salario as Single
3 DIM Horas as Single
4 DIM Total as Single
5 Salario = 5
6 Horas = 8
7 Total = Salario * Horas * Horas
8 PRINT “el salario semanal del empleado es”
9 PRINT Total
10 END
11
9. 14. En un aula de clase hay 42 alumnos queesta divididoen 30 mujeres y 12
varones calcular el porcentaje
1 PUBLIC SUB main ( )
2 DIM Mujeres AS Integer
3 DIM Varones AS Integer
4 DIM Suma AS Integer
5 DIM P1 AS Integer
6 DIM P2 AS Integer
7 Mujeres = 30
8 Varones = 12
9 Suma = Mujeres + Varones
10 P1 = Mujeres / Suma * 100
11 P2 = Varones / Suma * 100
12 PRINT “el porcentaje de mujeres y varones es”
13 PRINT “mujeres :” & P1 & “%”
14 PRINT “Varones:” & P2 & “%”
15 END
16
15.Programa que permite ingresar el valor de un producto, y el númerode
unidades del mismo,mostrar por pantalla el total de importaciones, y
también que muestre la comisión del 15% en consola
1 PUBLIC SUB main ( )
2 DIM N_producto AS String
3 DIM V_producto AS Single
4 DIM Unidades AS Integer
5 DIM Importacion AS Single
6 DIM Comision AS Single
7 DIM V_total AS Single
8 PRINT “ingrese el nombre de su producto”
9 INPUT N_producto
10 PRINT “ingrese el valor por producto”
11 INPUT V_producto
12 PRINT “ingrese la unidades de su producto”
13 INPUT Unidades
14 Importacion = Unidades * V_producto
15 PRINT “el total de la importaciones”
16 PRINT “la comisión del 15%”
17 PRINT Comision
18 V_total = Comision + Importacion
19 PRINT “el total por el producto la venta es :”
20 PRINT N_producto & V_total
21 END
10. Su sintaxi es:
Select[case ] expresión
[case expresión[to expresión # 2][,…]
…]
[ case expresión[to expresión #2][,…]
..]
[{case else l default}
…]
End select
16. Select case
Veamos como se aplica al mismo ejemplo anterior de las edades:
1 PUBLIC SUB Main ( )
2
3 DIM edades AS Integer
4 ...
5 SELECT CASE edades
6 CASE 0 TO 2
7 PRINT “BEBE”
8 CASE 2 TO 12
9 PRINT “NIÑO”
10 CASE 18
11 PRINT “BINGOYA PUEDES VOTAR”
12 CASE 13 TO 17
13 PRINT “JOVEN”
14 CASE ELSE
15 PRINT “ADULTO”
16
17 END
Se trata de un código mucho mas fácil que leer que el anterior.
11. 17.Ejemplos:
Aplicar un select case para determinar el descuento q se otorga en la próxima compra a un
cliente habitual. Y dicho cliente cuenta con tarjeta de crédito de la tienda “RETAIR” y el
descuento está relacionado al monto de su factorización del mes de enero se consirera 4 niveles
de factorización.
MONTO DE FACTURADO
ENERO
DESCUENTO DE LA
PRÓXIMA COMPRA
>450 40%
>300 y <=450 30%
>150 y <=300 20%
<150 10%
1 PUBLIC SUB Main ( )
2
3 DIM DES AS Integer
4 DIM FAC AS Integer
5 ...
6 SELECT case DES
7 CASE 0 TO 150
8 FAC = 10
9 CASE 151 TO 300
10 FAC = 20
11 CASE 301 TO 450
12 FAC = 30
13 CASE > 450
14 FAC = 40
15 CASE ELSE
16 PRINT “PARA LA PROXIMA COMPRA TENDRA UN DESCUENTODEL: ”
17 PRINT FAC& ”%”
18 END SELECT
12. Promediar notas de un x estudiante.
PROMEDIO
9 - 10 DAR
7 - 8.99 AAR
4.01 - 6.99 PARA
< = NAAR
1 PUBLIC SUB Main ( )
2 DIM A AS Single
3
4 PRINT “INGRESE UN VALOR”
5 INPUTA
6 ...
7 SELECT case
8 Case A > = 9 DO A < = 10
9 PRINT “DAR ”
10 ELSE
11 Case A > = 7 DO A < = 8.99
12 PRINT “AAR ”
13 ELSE
14 Case A < = 6.99
15 PRINT “PAAR ”
16 ELSE
17 Case A < = 4
18 PRINT “NAAR ”
19 END SELECT
20 END
13. 19.Definir cuál valor es mayor.
18.SENTENCIA IF
A B C
1 PUBLIC SUB Main ( )
2
3 DIM A AS Integer
4 DIM B AS Integer
5 DIM C AS Integer
6 PRINT “INGRESE UN VALOR”
7 INPUTA
8 PRINT “INGRESE OTRO VALOR”
9 INPUTB
10 PRINT “INGRESE UN ULTIMO VALOR”
11 INPUTC
12 ...
13 IF A > B AND A > C
14 PRINT “MAYOR ES A ”
15
16 IF B > C AND B > A
17 PRINT “MAYOR ES B ”
18
19 ELSE
20
21 PRINT “MAYOR ES C ”
22
23 ENDIF
14. 20. Forma de pago:1. 2, o 3.
Si es 1 el descuento será 10% del valor.
Si es 2 será 15%.
Si es 3 no habrá descuento.
1 PUBLIC SUB Main ( )
2
3 DIM A AS Single
4 DIM FP AS Integer
5 DIM DES1 AS Single
6 PRINT “INGRESE UN VALOR”
7 INPUTA
8 PRINT “INGRESE UNA FORMA DE PAGO ”
9 INPUT FP
10 ...
11 IF FP = 1 THEN
12 DES1 = (A * 10 )/100
13 PRINT “EL DESCUENTO SERA DE : ” DES1
14 ELSE
15
16 IF FP = 2 THEN
17 DES1 = (A * 15 )/100
18 PRINT “EL DESCUENTO SERA DE : ” DES1
19 ELSE
20 PRINT “NO HABRA DESCUENTO ”
21
22 ENDIF
15. 21.Definir el valor de un numero:
Positivo, Negativo, Neutro
1 PUBLIC SUB Main ( )
2
3 DIM A AS Single
4
5 PRINT “INGRESE UN VALOR”
6 INPUTA
7 ...
8 IF A > 0
9 PRINT “POSITIVO ”
10 ELSE
11 IF A < 0
12 PRINT “NEGATIVO ”
13 ELSE
14 IF A = 0
15 PRINT “NEUTRO ”
16
17 ENDIF
16. Su sintaxis es:
22.SENTENCIA FOR
For variable =expresion to expresion {step expresion }
…
Ejemplos:
Sepuede especificar valores negativos deforma queseconvertiráen una cuentaotros ejemplos:
1 PUBLIC SUB Main ( )
2
3 DIM N AS Integer
4
5 FOR N = 10 FOR 1 STEP - 1
6 PRINT N
7
8 NEXT
Si se quiereinterrumpirun bucleen algún punto, sepuedeusar la sentencia break:
1 PUBLIC SUB Main ( )
2
3 DIM N AS Integer
4
5 FOR N = 10 FOR 1 STEP - 1
6 IF N > 3 THEN BREAK
7 PRINT N
8 NEXT
El bucleacabaría cuandon valiera 3 y no escribiránlos últimos 3 números, también sedispone
de la sentencia continuequepermitesaltarsepasos en bucle.
1 PUBLIC SUB Main ( )
2
3 DIM N AS Integer
4
5 FOR N = 1 TO 4
6 IF N > 2 THEN CONTINUE
7
8 NEXT
17. Se sataria el dos al escribir los valores de N. existe una variante del bucle for que se usa al
irrecorrer.
23.Ejercicios:
24. Realiza un programautilizando la sentencia for paramostrar 10 veces la
palabra“AMISTAD”.
1 PUBLIC SUB Main ( )
2
3 DIM A AS Integer
4
5 FOR A = 1 TO 10
6 LISBOX.ADD(A)
7
8 NEXT
25. REALIZAR UNA APLICACIÓNQUEMUESTRELOS MULTIPLOS DE3 HASTA
EL 99.
1 PUBLIC SUB Main ( )
2
3 DIM B AS Integer
4
5 FOR B = 3 TO 99 STEP 3
6 LISBOX.ADD(B)
7
8 NEXT
18. 26. EJERCICIOS DE CONSOLA
PARA REALIZAR PROGRAMAS O APLICACIONES GRAFICAS HAREMOS LO SIGUIENTE:
1.ESCOGER NUEVO PROYECTO.
20. 5.ESCRIBIREMOS EL TITULO Y EL NOMBRE DE NUESTRA APLICACIÓN.
6.LISTO YA HEMOS CREADO NUESTRO PROYECTO.
21. 27.AHORA EMPESAREMOS A CREAR LA INTERFAZ GRAFICA DE NUESTRA
APLICACIÓNCONLAS HERRAMIENTAS QUEPOSEE GAMBAS Y PODER
EDITAR SUS PROPIEDADES.
CAJA DE HERRAMIENTAS EDITOR DE PROPIEDADES
28. EJERCICIO:
29. CALCULADORABASICA:
PARA REALIZAR ESTA CALCULADORA BASICA UTILIZAMOS DE LA CAJA DE
HERRAMIENTAS:
LABEL
TEXTBOX
BOTTON
LA CODIFICACION UTILIZADA SERIA:
22. 1 PUBLIC SUB _new()
2 END
3
4 PUBLIC SUB Form_Open()
5 END
6
7 PUBLIC SUB Dial1_Change()
8 END
9
10 PUBLIC SUB RadioButton1_Click()
11 END
12
13 PUBLIC SUB ListBox1_Click()
14 END
15
16 PUBLIC SUB Label2_MouseDown()
17 END
18
19 PUBLIC SUB Label4_MouseDown()
20 END
21
22 PUBLIC SUB TextBox1_KeyPress()
23 END
24
25 PUBLIC SUB Button3_Click()
26 END
27
28 PUBLIC SUB Button4_Click()
29 END
30
31 PUBLIC SUB btnSuma_Click()
32 txtresul.text=txtprival.text+txtsegval.Text
33 END
34
35 PUBLIC SUB Button1_Click()
36 END
37
38 PUBLIC SUB btnLimpiar_Click()
39 txtprival.txt=""
40 txtsegval.txt=""
41 txtresul.txt=""
42 END
43
44 PUBLIC SUB btnSalir_Click()
45 ME.Close
46 END
47
48 PUBLIC SUB btnResta_Click()
49 txtresul.text=txtprival.text- txtsegval.Text
50 END
51
52 PUBLIC SUB btnMulti_Click()
53 txtresul.text=txtprival.text*txtsegval.Text
54 END
55
56 PUBLIC SUB btnDiv_Click()
57 txtresul.text=txtprival.text/txtsegval.Text
58 END
59
60 PUBLIC SUB txtsegval_KeyPress()
61 END
62
63
64
65
66
67
68
23. 30. APLICACIÓNPARA LA EDAD:
PARA REALIZAR ESTA APLICACION UTILIZAMOS DE LA CAJA DE HERRAMIENTAS:
LABEL
TEXTBOX
BOTTON
LA CODIFICACION UTILIZADA SERIA:
24. 1 PUBLIC SUB _new()
2 END
3
4 PUBLIC SUB Form_Open()
5 END
6
7 PUBLIC SUB Label4_MouseDown()
8 END
9
10 PUBLIC SUB Label3_MouseDown()
11 END
12
13 PUBLIC SUB btnejecutar_Click()
14 DIM edadAS Integer
15 edad= txtedad.Text
16 IF edad< 2 AND edad> 0 THEN
17 txtresul.Text="bebe.."
18 ELSE
19 IF edad< 12 THEN
20 txtresul.Text="niño.."
21 ELSE
22 IF edad< 18 THEN
23 txtresul.Text="adolecente.."
24 ELSE
25 txtresul.Text="adulto.."
26 ENDIF
27 ENDIF
28 ENDIF
29 END
30
31 PUBLIC SUB btnlimpiar_Click()
32 txtnombre.Text=""
33 txtedad.Text=""
34 txtresul.Text=""
35 END
36
37 PUBLIC SUB btnsalir_Click()
38 ME.Close
39 END
40
41
42
43
44
45
46
47
48
49
50
51
52
26. 1 PUBLIC SUB _new()
2 END
3
4 PUBLIC SUB Form_Open()
5 END
6
7 PUBLIC SUB Button3_Click()
8 END
9 PUBLIC SUB btnlimp_Click()
10 txtnumero.Text=""
11
12 END
13 PUBLIC SUB btnsalir_Click()
14 ME.Close
15 END
16
17 PUBLIC SUB btnejecut_Click()
18 DIM numeroASInteger
19 DIM a AS Integer
20 numero= txtnumero.Text
21 a = numeroMOD 2
22 IF a <= 0
23 Message("PAR")
24 ELSE
25 Message( "impar")
26 ENDIF
27 END