Clase 05 visual.net 2010 rivera g

459 views

Published on

Mi Web: riverasn.p.ht

Published in: Education
  • Be the first to comment

  • Be the first to like this

Clase 05 visual.net 2010 rivera g

  1. 1. Company.Rivera & G Autor: Santos Nilo Rivera Luján Mi Web: riverasn.p.ht 1 Bucles Repetitivos Son aquellos que realizan instrucciones repetidas veces. Pueden ser condicionales o automática. Tipos I) Bucles ejecutados por el usuario Son realizados por el mismo usuario II) Bucles con sintaxis  Bucles de entrada controlada  Bucles de salida Controlada  Bucles con contador automático a) Bucles de entrada controlada Do while <condición> Instrucciones [EXIT DO] Loop b) Bucles de salida controlada Do Instrucciones [EXIT DO] Loop while <condición> c) Bucles con contador automtico For Valor Inicial to Valor Final [Step #] Instrucciones [EXIT FOR] Next Contador Se caracterizan por contar procesos y generar series Características Contador=Valor inicial (FUERA DEL BUCLE) Contador=Contador+incremento fijo (DENTRO DEL BUCLE) Acumulador Se caracterizan por acumular valores Características Acumulador=Valor inicial (FUERA DEL BUCLE) Acumulador=Acumulador + incremento variable (DENTRO DEL BUCLE) Multiplicador Se caracteriza por incrementarse geométricamente. Características Multiplicado=Valor Inicial (FUERA DEL BUCLE)
  2. 2. Company.Rivera & G Autor: Santos Nilo Rivera Luján Mi Web: riverasn.p.ht 2Multiplicador=Multiplicador x Incremento multiple (DENTRO DEL BUCLE) Ejemplo: Programa para generar la serie: 1 2 3 4 5 Public Class Frminicial Private Sub Btnord_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btnord.Click Dim n As Integer = 0, cad As String = "" Do While n < 5 n = n + 1 cad = cad + Str(n) + " " Loop Lbls.Text = cad End Sub Private Sub Btnord2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btnord2.Click Dim n As Integer = 0, cad As String = "" Do n = n + 1 cad = cad + Str(n) + " " Loop While n < 5 Lbls.Text = cad End Sub Private Sub Btnord3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btnord3.Click Dim n As Integer, cad As String = "" For n = 1 To 5 cad = cad + Str(n) + " " Next Lbls.Text = cad End Sub End Class
  3. 3. Company.Rivera & G Autor: Santos Nilo Rivera Luján Mi Web: riverasn.p.ht 3 Desarrollar Programa para generar la siguiente serie: 1 , 5 , 9 , 13 , 17 Public Class Form1 Private Sub Btnord_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btnord.Click Dim n As Integer Dim cad As String = "" For n = 1 To 17 Step 4 cad = cad + Str(n) + " " Next Lbls.Text = cad End Sub End Class Programa para generar la siguiente serie : 10, 5, 0, -5, -10 Public Class Frm2 Private Sub Btnord_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btnord.Click Dim n As Integer Dim cad As String = "" For n = 3 To 11 Step 2 cad = cad + Str(n) + "/" + Str(n + 2) + " " Next Lbls.Text = cad End Sub End Class
  4. 4. Company.Rivera & G Autor: Santos Nilo Rivera Luján Mi Web: riverasn.p.ht 4 Programa para generar la serie: 3/5 5/7 7/9 9/11 11/13 Public Class Frm2 Private Sub Btnord_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btnord.Click Dim n As Integer Dim cad As String = "" For n = 3 To 11 Step 2 cad = cad + Str(n) + "/" + Str(n + 2) + " " Next Lbls.Text = cad End Sub End Class Programa para generar la serie : 1/2, 2/4, 3/6, 4/8, 5/10 Public Class Frm3 Private Sub Btnord_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btnord.Click Dim n As Integer Dim cad As String = "" For n = 1 To 5 cad = cad + Str(n) + "/" + Str(n * 2) + " " Next Lbls.Text = cad End Sub End Class Programa para generar la serie: 2 ,4, 8, 16, 32
  5. 5. Company.Rivera & G Autor: Santos Nilo Rivera Luján Mi Web: riverasn.p.ht 5 Programa para generar la serie y hallar la suma de: -100, -80, -60, - 40, -20 Public Class Frm5 Private Sub Btnord_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btnord.Click Dim n As Integer, s As Integer Dim cad As String = "" For n = -100 To 0 Step 20 cad = cad + Str(n) + " " s = s + n Next Lbls.Text = cad Lblsum.Text = s End Sub End Class
  6. 6. Company.Rivera & G Autor: Santos Nilo Rivera Luján Mi Web: riverasn.p.ht 6 MISCELANEA DE LISTAS, COMBOS Y BUCLES Ejercicio Nro1 Private Sub Button1_Click(...) Dim n As Integer, i As Integer, sue As Integer n = Val(TextBox1.Text) For i = 1 To n sue = Val(InputBox("Ingrese Sueldo", "FOR")) Next End Sub Ejercicio Nro2 Private Sub Button1_Click(...) Dim n As Integer, i As Integer, sue As Integer, s As Integer n = Val(TextBox1.Text) For i = 1 To n sue = Val(InputBox("Ingrese Sueldo", "FOR")) s = s + sue Next Label4.Text = s End Sub
  7. 7. Company.Rivera & G Autor: Santos Nilo Rivera Luján Mi Web: riverasn.p.ht 7 Ejercicio Nro3 Private Sub Button1_Click(...) Dim n As Integer, i As Integer, sue As Integer, may As Integer n = Val(TextBox1.Text) For i = 1 To n sue = Val(InputBox("Ingrese Sueldo", "FOR")) If i = 1 Then may = sue Else If sue > may Then may = sue End If Next Label4.Text = may End Sub Ejercicio Nro4 Private Sub Button1_Click(...) Dim n As Integer, i As Integer, sue As Integer, men As Integer n = Val(TextBox1.Text) For i = 1 To n sue = Val(InputBox("Ingrese Sueldo", "FOR")) If i = 1 Then men = sue Else
  8. 8. Company.Rivera & G Autor: Santos Nilo Rivera Luján Mi Web: riverasn.p.ht 8If sue < men Then men = sue End If Next Label4.Text = men End Sub Ejercicio Nro5 Private Sub Button1_Click(...) Dim n As Integer, i As Integer, sue As Integer n = Val(TextBox1.Text) Do While i < n i = i + 1 sue = Val(InputBox("Ingrese sueldo", "Do While **** loop")) Loop End Sub Private Sub Button1_Click(...) Dim n As Integer, i As Integer, sue As Integer n = Val(TextBox1.Text) Do i = i + 1 sue = Val(InputBox("Ingrese sueldo", "Do While **** loop")) Loop While i < n End Sub
  9. 9. Company.Rivera & G Autor: Santos Nilo Rivera Luján Mi Web: riverasn.p.ht 9Ejercicio Nro6 Private Sub Button1_Click(...) Dim n As Integer, i As Integer, s As Integer ListBox1.Items.Add(TextBox1.Text) ListBox2.Items.Add(TextBox2.Text) TextBox1.Text = "" TextBox2.Text = "" n = ListBox2.Items.Count For i = 0 To n - 1 s = s + Val(ListBox2.Items.Item(i)) Next Label4.Text = s End Sub Private Sub Button2_Click(...) ListBox1.Items.Clear() ListBox2.Items.Clear() Label4.Text = "" End Sub
  10. 10. Company.Rivera & G Autor: Santos Nilo Rivera Luján Mi Web: riverasn.p.ht 10Ejercicio Nro7 Private Sub Form_Load(…) ListBox1.Items.Add("Juan Perez") ListBox2.Items.Add("1200") ListBox3.Items.Add("200") ListBox1.Items.Add("Ana Pelaez") ListBox2.Items.Add("600") ListBox3.Items.Add("80") ListBox1.Items.Add("Pedro Juarez") ListBox2.Items.Add("800") ListBox3.Items.Add("120") ListBox1.Items.Add("Luz Huaman") ListBox2.Items.Add("1500") ListBox3.Items.Add("300") ListBox1.Items.Add("Carmen Li") ListBox2.Items.Add("1700") ListBox3.Items.Add("290") End Sub Private Sub ListBox1_SelectedIndexChanged Dim pos As Integer, sue As Integer, bon As Integer, pt As Integer pos = ListBox1.SelectedIndex ListBox2.SelectedIndex = pos ListBox3.SelectedIndex = pos sue = Val(ListBox2.Items.Item(pos)) bon = Val(ListBox3.Items.Item(pos)) pt = sue + bon Label5.Text = ListBox1.Items.Item(pos) Label7.Text = pt
  11. 11. Company.Rivera & G Autor: Santos Nilo Rivera Luján Mi Web: riverasn.p.ht 11End Sub Ejercicio Nro8 Private Sub Form8_Load(...) ListBox1.Items.Add("Matematicas") ListBox1.Items.Add("Lenguaje") ListBox1.Items.Add("Visual Basic Net") ListBox1.Items.Add("UML") ListBox1.Items.Add("Historia") ListBox1.Items.Add("Ingles") End Sub Private Sub Button1_Click(...) Dim pos As Integer pos = ListBox1.SelectedIndex If pos = -1 Then Exit Sub ListBox2.Items.Add(ListBox1.Items.Item(pos)) ListBox1.Items.RemoveAt(pos) End Sub Private Sub Button2_Click(...) Dim n As Integer, i As Integer n = ListBox1.Items.Count For i = 0 To n - 1 ListBox2.Items.Add(ListBox1.Items.Item(i)) Next ListBox1.Items.Clear() End Sub Private Sub Button3_Click(...) Dim pos As Integer pos = ListBox2.SelectedIndex If pos = -1 Then Exit Sub ListBox1.Items.Add(ListBox2.Items.Item(pos)) ListBox2.Items.RemoveAt(pos)
  12. 12. Company.Rivera & G Autor: Santos Nilo Rivera Luján Mi Web: riverasn.p.ht 12End Sub Private Sub Button4_Click(...) Dim n As Integer, i As Integer n = ListBox2.Items.Count For i = 0 To n - 1 ListBox1.Items.Add(ListBox2.Items.Item(i)) Next ListBox2.Items.Clear() End Sub Trabajo Nro 7:Bucles y Funciones Predefinidas en el proyecto: Bucles_Apellidos_Nombres Programa para generar las siguientes series: a) 25 30 35 40 45 b) -1 -10 -19 -28 -37 c) 3 9 27 81 243 Programa para generar los n terminos de las series a) 2 5 8 11 . . . b) 100 40 -20 -80 . . . c) 8/3 12/5 16/7 20/9 . . . Programa para generar la suma de las siguientes series a) 3 6 9 12 15 b) -3 -9 -15 -21 -27 -33 c) 1/2 4/3 9/4 16/5 25/6 Programa para generar el producto de las siguientes series a) 1 2 3 4 5 b) 2 4 6 8 10 c) -5 -3 -1 1 3 Programa para ingresar el apellido, unidad1,unidad2 de n alumnos del curso de Computo II de la Escuela de Ing. Industrial y determine: a)La cantidad de aprobados b) La cantidad de jalados c) La cantidad de aprobados con promedio mayor de 14 d) La cantidad de aprobados con promedio entre 16 y 20 e) El mayor promedio f) El menor promedio y a quien pertenece g) El promedio de aula Nota: Use Inputbox y además Promedio = Unidad1 + Unidad 2 2 Promedio de Aula = Suma de promedios N
  13. 13. Company.Rivera & G Autor: Santos Nilo Rivera Luján Mi Web: riverasn.p.ht 13For Un1=val(inputbox(“ingrese nro1”, “colegio”)) Un2=val(inputbox(“ingrese nro2”, “colegio”)) P =(uni1+uni2)/2 S=s+p next Mi grupo de programadores : https://www.facebook.com/groups/398604720248657/

×