Realizar un programa que pida las notas de 10 alumnos por pantalla y muestre un menú́ de opciones: 1. Listar notas, 2. Calcular la media, 3. Calcular el menor, 4. Calcular el mayor.
Formulario Completo:
Public Class Form1
Dim VecCal(9) As Double
Dim fila As Integer = 0
Dim S As Double
Dim P As Double
Dim C As Integer
Private Sub GUARDAR()
If TextBox1.Text >= 0 And TextBox1.Text <= 10 Then
If fila < 10 Then
VecCal(fila) = CInt(TextBox1.Text)
fila = fila + 1 'pasa a la siguiente posicion
MsgBox("Se ha guardado tu calificacion", MsgBoxStyle.Information, MsgBoxStyle.OkOnly)
TextBox1.Text = ""
TextBox1.Focus()
Else
MsgBox("Base de datos llena")
End If
Else
MsgBox("Calificacion no valida")
End If
End Sub
Private Sub MEDIA()
S = 0
For I = 0 To 9
S = S + VecCal(I)
Next
P = S / 10
LabelPromedio.Text = P
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub ButtonGuardar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonGuardar.Click
GUARDAR()
End Sub
Private Sub ButtonPromedio_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonPromedio.Click
MEDIA()
End Sub
Private Sub ButtonLista_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonLista.Click
For I = 0 To 9
C = VecCal(I)
ListBox1.Items.Add(C)
Next
End Sub
Private Sub ButtonMenor_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonMenor.Click
Array.Sort(VecCal)
LabelMenor.Text = VecCal(0).ToString
End Sub
Private Sub ButtonMayor_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonMayor.Click
Array.Sort(VecCal)
LabelMayor.Text = VecCal(9).ToString
End Sub
End Class
Imagen mostrando cuando solo acepta números mayores o iguales a 0 y menores o iguales a 10:
Imagen mostrando cuando solo acepta 10 calificaciones:
Imagen mostrando la lista, la media, el mayor y menor calificación
:



No hay comentarios:
Publicar un comentario