PROCEDIMIENTOS Y FUNCIONES EN VB .NET
Objetivos:
- Practicar el uso de procedimientos y funciones.
- Diferenciar funciones de procedimientos.
1. Escriba un procedimiento que imprima la fecha y hora actual.
3. Escriba una aplicación para capturar el número de teléfono de 5 participantes y que posea un procedimiento que seleccione e imprima de forma aleatoria el número de teléfono ganador.
--------------------------------------------------------------------------------------------------------------
Module Module2
Sub main()
Dim cel1, cel2, cel3, cel4, cel5 As String
Console.Write("Numero 1: ")
cel1 = Console.ReadLine
Console.Write("Numero 2: ")
cel2 = Console.ReadLine
Console.Write("Numero 3: ")
cel3 = Console.ReadLine
Console.Write("Numero 4: ")
cel4 = Console.ReadLine
Console.Write("Numero 5: ")
cel5 = Console.ReadLine
ganador(cel1, cel2, cel3, cel4, cel5)
Console.ReadLine()
End Sub
------------------------------------------------------------------------------------------------------------
Sub Ganador(cel1 As String, cel2 As String, cel3 As String, cel4 As String, cel5 As String)
Dim r As New Random
Randomize()
Select Case r.Next(1, 5)
Case 1
Console.Write("Ganó el: " & cel1)
Case 2
Console.Write("Ganó el: " & cel2)
Case 3
Console.Write("Ganó el: " & cel3)
Case 4
Console.Write("Ganó el: " & cel4)
Case 5
Console.Write("Ganó el: " & cel5)
End Select
End Sub
End Module
--------------------------------------------------------------------------------------------------------------
7. Escriba una aplicación para calcular la nota final de un alumno, utilizando el sistema de evaluación de la materia programación I, crear una sola función que permita calcular la nota promedio de cada periodo
--------------------------------------------------------------------------------------------------------------
Module Module3
Sub main()
Dim nota1, nota2, nota3, prom1, prom2, prom3, final As Decimal
Console.WriteLine("Calcule la nota final de un alumno:")
Console.WriteLine()
Console.WriteLine("PERIODO 1")
Console.WriteLine("Ingrese nota 1")
nota1 = Console.ReadLine()
Console.WriteLine("Ingrese nota 2")
nota2 = Console.ReadLine()
Console.WriteLine("Ingrese nota 3")
nota3 = Console.ReadLine()
prom1 = prom(nota1, nota2, nota3)
Console.Clear()
'---------------------------------------------
Console.WriteLine("PERIODO 2")
Console.WriteLine("Ingrese nota 1")
nota1 = Console.ReadLine()
Console.WriteLine("Ingrese nota 2")
nota2 = Console.ReadLine()
Console.WriteLine("Ingrese nota 3")
nota3 = Console.ReadLine()
prom2 = prom(nota1, nota2, nota3)
Console.Clear()
'---------------------------------------------
Console.WriteLine("PERIODO 3")
Console.WriteLine("Ingrese nota 1")
nota1 = Console.ReadLine()
Console.WriteLine("Ingrese nota 2")
nota2 = Console.ReadLine()
Console.WriteLine("Ingrese nota 3")
nota3 = Console.ReadLine()
prom3 = prom(nota1, nota2, nota3)
Console.Clear()
Console.WriteLine("RESULTADOS")
Console.WriteLine()
Console.WriteLine("Periodo 1: " & prom1)
Console.WriteLine("Periodo 2: " & prom2)
Console.WriteLine("Periodo 3: " & prom3)
final = (prom1 + prom2 + prom3) / 3
Console.WriteLine()
Console.WriteLine("Nota final: " & FormatNumber(final, 1))
Console.ReadLine()
End Sub
--------------------------------------------------------------------------------------------------------------
Function prom(ByVal x As Decimal, ByVal y As Decimal, ByVal z As Decimal)
Dim total As Decimal
total = ((x * 0.25) + (y * 0.25) + (z * 0.5))
'cada promedio
'en este formato 25% + 25% de actividades y 50% de parcial.
Return FormatNumber(total, 1)
End Function
End Module
--------------------------------------------------------------------------------------------------------------



No hay comentarios:
Publicar un comentario